Gradle custom task for banks

I am using Gradle for my Java project, and I was wondering if it is possible to prevent the gradle buildjar file from being generated every time it is executed.

Also, is it possible to create a custom task to create Jar with dependencies in a specific place build/myAppJar/.

Here is what I have done so far for a custom task:

task toJar (type: Jar) {
    from configurations.compile.collect { zipTree it }
    manifest {
        attributes 'Implementation-Title': 'myApp',
                'Implementation-Version': 1.0,
                'Main-Class': mainClassName
    }
}

The above code will create a jar file under build/libs, and the file does not contain compiled files, but only dependencies.

Thank!

+4
source share
1 answer

The task buildcomes from the plugin java. You can control when a jar is built with something like this:

jar {
  onlyIf { condition }
}

jar, , - , , false, .

toJar , .

task toJar (type: Jar) {
    from sourceSets.all
}

, : from configurations.compile.collect

ref: Gradle java plugin

+4

All Articles