This is a simple development project base you can build upon and customize to jumpstart a new Gradle + Scala project, instead of starting from scratch. The template provides a skeleton with a range of options from which you can choose to keep only those relevant for your project.
The project base includes:
- template HOCON config file
- config file loading based on filepath from input args using PureConfig magic
- template log4J setup
- ScalaTest
- Gradle shadowJar (fatJAR) building with commit hash recorded in its Manifest
- Gradle TAR distribution packaging the fatJAR with additional resources and the configuration file
- Gradle template setup for docker image building (just the Gradle side of things, no Dockerfile)
- a template bash script to fill in with any pre-processing you need and trigger the JAR (if Docker is being used, this can be your Docker entrypoint)
- a base for keeping multiple configuration files and dynamically loading the correct one based on
env
build property
- git
- Use GitHub's Use this template feature to start your own repository with this structure or run
git clone https://github.com/holuond/gradle_scala_dev_project_base
. - In your IDE, create a new project from existing sources (select the
build.gradle
file). - Run
gradlew clean build --info
to build the project. - (Recommended) Replace all placeholder values. Search for all occurrences of
your.app
,your.pckg
andyour.repo
and replace them with your custom values based on the context. Also replaceyour/package
in the path undersrc/main/your/package
andsrc/test/your/package
and rename the root project directory. - (Optional) If you require a different Gradle version then provided via the wrapper, run
gradle wrapper
if you have a local Gradle installation or usegradlew wrapper --gradle-version <version>
.
- You can choose to only use the part of the setup that outputs a distribution archive containing a HOCON config
file, logging configuration and a fatJar and remove the Docker setup from
build.gradle
. Then, you can run the following to build and package the distribution tar archive:And then you simply unpack the distribution and run the jar:gradlew clean distTar --info
dist_dir='your/project/build/distributions' artifact_name='example-0.0.1-SNAPSHOT' dist="$dist_dir/$artifact_name" if [ ! -d $dist ]; then tar -xf $dist.tar --directory $dist_dir fi $dist/bin/run.sh -j $dist/lib/$artifact_name-all.jar -c $dist/conf/application.conf -l $dist/conf/log4j.xml
- Or you can wrap the output distribution archive in a Docker image. In that case, you can use the prepared
docker
task in thebuild.gradle
file and connect it and its build arguments to your Dockerfile (where you can consume the ARGs from thedocker
task). You can leveragerun.sh
as your Docker entrypoint.