Diolor
Diolor

Reputation: 13450

Gradle extend task / Create task based on task

New to Groovy, gradle. I want to extend the following task (part of java plugin):

jar {
    from { configurations.runtime.collect { zipTree(it) } }

    manifest.attributes( 'Implementation-Title': archivesBaseName,
                'Implementation-Version': version,
                'Main-Class': mainClassName,
                'Built-By': POM_DEVELOPER_NAME
    )
}

The extended task will have

archiveName = 'PJ-latest.jar'
destinationDir = project.getRootDir()

In typical Java I would have called super but I'm not sure how I can do it in gradle. My best try is to extend the Jar class add the same parameters as jar has and also the dependencies:

task assembleCompiler(type: Jar){
    dependsOn compileJava, processResources, classes

    archiveName = 'PJ-latest.jar'
    destinationDir = project.getRootDir()

    from { configurations.runtime.collect { zipTree(it) } }

    manifest.attributes( 'Implementation-Title': archivesBaseName,
            'Implementation-Version': version,
            'Main-Class': mainClassName,
            'Built-By': POM_DEVELOPER_NAME
    )
}

Upvotes: 2

Views: 4004

Answers (1)

Peter Niederwieser
Peter Niederwieser

Reputation: 123900

You'll have to configure the second task separately, like you already did. If you want to share this code, turn it into a plugin.

Upvotes: 2

Related Questions