Gradle running on OpenJDK8.
This image provides:
- SHA256 check of the downloaded gradle artifact
- caching of the dependencies downloaded during the first build
- option to run the build with a given user instead of
root
docker run --rm -v `pwd`:/project -u `id -u`:`id -g` metahelicase/gradle build
The container's arguments are directly passed to gradle.
When no argument is specified, the container runs gradle with --version
.
The container requires that the project folder is mounted to the /project
volume.
This can be achieved by running
docker run --rm -v /home/myself/projects/myproject:/project metahelicase/gradle build
or if you are inside the project folder
docker run --rm -v `pwd`:/project metahelicase/gradle build
When running gradle inside the container, the build artifacts are generated by the container's user, which is root
by default.
After the build you may find that your build
folder and the files inside it are owned by root
.
This may be not a problem when running the container on a CI server, but when using it during development you may have to use chown
to restore the files' ownership.
Docker provides the -u
option, which can be used to run a container with a different user id and group id.
The generated build artifacts are owned by the user declared by the -u
option.
The user id and group id must be numbers, not the names that identify them.
If not specified, the default user is 0:0
(root
).
You can find out which user id and group id you have by running
id -u
id -g
The project build can be run as the host user with
docker run --rm -v `pwd`:/project -u `id -u`:`id -g` metahelicase/gradle build
The project dependencies are stored under the project folder, inside the .gradle/caches
directory.
After the first build, gradle uses the stored dependencies instead of downloading them again.
The maven repository is located inside the container at /gradle/.m2
.
Mount the host repository to use maven dependencies and publish artifacts, by adding the option
-v $HOME/.m2:/gradle/.m2