Basically my project exposes API over http and websocktes. Nobody can use it as a dependency. So I don’t see any reason to use jar. I know it may sounds weird, but I want to test this idea.
I’m using embedded jetty and I run my project just as java -java app.jar app.conf.
I tried to unzip my jar file and run it as java -cp .:lib/* com.example.Main app.conf and it did worked.
So I want to put all files that gradle puts to jar file to folder without archiving it. After that I can just rsync folder to server or copy it to docker container.
What is the simplest way to do this with gradle?
I can probably do it by using jar.eachFile, just copy files to folder.
jar.eachFile {
println it
}
Maybe there is an easiest way just with one Copy task.
There’s a slight difference between into(...) and into(...) {...} here. The former configures the root copy spec, and the latter configures a child copy spec. The child copy spec into is relative to the root copy spec into. So, you’re copying configurations.compile into ${buildDir}/exploded/${buildDir}/exploded/lib.
You’d also typically want runtimeClasspath (or runtimeClasspath if you’re using recent versions and want to get off the deprecated configurations) over compile.
The easiest way to stop the jar task from running is to just disable it.
Together, it could look like this:
task explodedJar(type: Copy) {
with jar
into "${buildDir}/exploded"
into('lib') {
from configurations.runtimeClasspath
}
}
jar.enabled = false
assemble.dependsOn explodedJar