I'm still new to Docker and Gradle, but I'm trying to customize the Gradle assembly, which creates a Docker image.
I just finished configuring the Dockerfile , which locally deploys and launches the jar as expected. I have this in my build.gradle :
buildscript { repositories { mavenCentral() } dependencies { classpath 'se.transmode.gradle:gradle-docker:1.2' } } plugins { id 'com.github.johnrengelman.shadow' version '1.2.3' } apply plugin: 'docker' jar { manifest { attributes 'Main-Class': 'com.myapp.Main' } } task buildDocker(type: Docker, dependsOn: shadowJar) { push = false applicationName = jar.baseName tagVersion = 'latest' dockerfile = file('src/main/docker/Dockerfile') copy { from shadowJar into stageDir } }
I run ./gradlew build buildDocker to create an image. I am still satisfied with this.
I usually create a throwaway class (e.g. Playground.java ) using the main method, which I can start and ignore. I usually run this in the IDE, but now I would like to be able to connect to other Docker containers, which, as I know, will work.
I know that I can try to change the sourceSets I use by excluding com.myapp.Main , but I thought there might be a more elegant solution similar to this:
task buildDockerPlayground(type: Docker, dependsOn: shadowJar) { main = 'com.myapp.Playground' push = false applicationName = jar.baseName tagVersion = 'latest' dockerfile = file('src/main/docker/Dockerfile') copy { from shadowJar into stageDir } }
Another approach might be another task that I use to replace build when calling ./gradlew build buildDocker , for example. ./gradlew playground buildDocker . Is it more practical?
source share