0

I would like to have the default configuration from task "jar" from the java plugin for gradle, but I would also like to add several different configurations for different "jar" tasks. The way I am doing it now is just commenting out the jar tasks that I am not using.

Example:

//jar {
//  archiveName = 'a.jar'
//  include 'path/to/package/1/*'
//}

jar {
    archiveName = 'b.jar'
    include include 'path/to/package/2/*'
}

Is there a better way?

I am aware that I can create new tasks of type "Jar", but then I don't get that default configuration for free; I would have to provide it myself. Which is troublesome, since I don't know what that configuration is.

I am looking for something like:

task myJar(type: Jar, dependsOn: classes) {
    extends "jar"
    ...include additional configuration here
}

I have the same issue for other types of default tasks, not just "jar".

3
  • Commenting the tasks out is definitely not a good idea. Could you please clarify the scenario so it'll be easier to help.
    – Opal
    Aug 17, 2015 at 10:59
  • As I understand it, the "jar" task is a task of the type "Jar". The "jar" task also has some configurations that can be changed. I would like to have several different tasks of the type "Jar", all of which includes the same configuration as the pre-configured "jar" task. The first example I gave: I would like to have one jar task with one archive name, and another jar task with another name, without having to define my own task, or at least to be able to re-use the configuration of the "jar" task.
    – JonatanSJ
    Aug 17, 2015 at 12:57
  • Maybe task rules are what you are looking for: docs.gradle.org/current/userguide/userguide_single.html#N10F07 ?
    – Opal
    Aug 18, 2015 at 11:12

1 Answer 1

0

I found the way, simple, yet I found it very hard to find information about it.

Using the keyword "with" I can include another task's configs with the current task:

task(testJar, type: Jar) {
    archiveName = 'test.jar'
    with jar
}

Yields the same result as

jar {
    archiveName = 'test.jar'
}
1
  • Unfortunately, the with(sourceSpecs) method only worked for tasks of type "Jar"...
    – JonatanSJ
    Aug 18, 2015 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.