Replace default war task in maven-publish


(Josh) #1

Hi all,

I have a question. We have a running multi project build which creates war files. The war file needs to be customized a bit. I managed it with directly modifying the war task like:

war {
   from(...) // and so on
}

in that script we have an import of a script which manages the publishing via maven-publishing plugin:

apply plugin: 'maven-publish'
....
publishing {
    publications {
        mavenWar(MavenPublication) {

            artifact war 
             ...
         }
     }
}

So far everything works. Now I’d like to move the customization of that war file into a custom task which overwrites the default war target. Like:

task war(type: War, dependsOn: prepareLanguageFiles, overwrite: true) {
   from(...) 
    ...
}

The new war target itself works but the publishing won’t publish the same war file. It publishes the war created by the default war task. I assume it’s because the publishing section is imported before the actual “custom” war task is defined. Something with the configuration time?

Does anyone has an idea how I can make this work?


(Josh) #2

So basically I want to archive that maven-publish publishes the war created by my custom war task. The name of the task needs to be “war” :slight_smile:


(Josh) #3

If anyone has the same issue I found a solution which works for me. I guess it’s a hack :slight_smile:
I just added this to the gradle file which overwrites the default war task:

publishing.publications.mavenWar.artifacts = []
publishing.publications.mavenWar {
    artifact war
    artifact jarSources
}