Create and install second artifact with war and maven plugins


(Jake Cormier) #1

I am trying to create a WAR file, as well as a JAR file. I want to be able to install both to my mavenLocal. I am using the java, war and maven plugins.

I have description, group, archivesBaseName, and version declared, as well as repositories with mavenLocal() and mavenCentral(), and some dependencies.

This all creates and installs my WAR just fine. I now want to create and install a second artifact.

task myJar(type: Jar) {
    include('path/to/my/classes/*')
    manifest {
        attributes (
            'Implementation-Title':
   archivesBaseName,
            'Implementation-Version':
 project.version,
            'Build-Date' : new Date(),
            'Build-JDK'
: System.getProperty('java.version'),
            'Built-By'
 : System.getProperty('user.name'),
        )
    }
}
  uploadArchives {
    println "Archives Artifacts: " + configurations.archives.allArtifacts
    dependsOn myJar
    repositories {
        mavenDeployer {
            repository(url: mavenLocal().url)
            addFilter('war') {artifact, file ->
                artifact.ext == 'war'
            }
            addFilter('searchJar') {artifact, file ->
                artifact.ext == 'jar'
            }
        }
    }
}

The only artifact listed is the WAR, and I don’t get a JAR uploaded, although it was built and exists in my build/lib folder, alongside my WAR file.

I tried adding this:

artifacts {
    archives myJar
}

But that makes my “install” task fail because the POM can’t handle multiple main artifacts.

How do I get my JAR file installed?


(Peter Niederwieser) #2

You do need the ‘artifacts’ block, and I think you also need to add filters for ‘install.repositories.mavenInstaller’.