How to publish a snapshot war file

I’m learning how to use gradle. My build produces a war file. I would like to publish this to an Artifactory repository. No success so far.

I’ve tried to use uploadArchives

uploadArchives {
     repositories {
         mavenDeployer {
            repository {
                 url = "http://iaa44.papyrus.com/artifactory/libs-releases-local"
                  authentication = [
                  username: "deployer",
                  password: "xxxx"
                 ]
              }
         }
     }
}

Which produces

Caused by: java.lang.NullPointerException
        at org.apache.maven.artifact.ant.DeployTask.createDeploymentArtifactRepository(DeployTask.java:56)
        at org.apache.maven.artifact.ant.DeployTask.getDeploymentRepository(DeployTask.java:182)
        at org.apache.maven.artifact.ant.DeployTask.doExecute(DeployTask.java:115)
        at org.gradle.api.publication.maven.internal.ant.CustomDeployTask.doExecute(CustomDeployTask.java:39)

And maven-publish

publishing {
    publications {
        mavenWeb(MavenPublication) {
            from components.web
        }
    }
    repositories {
        maven {
         url "http://iaa44.papyrus.com/artifactory/libs-snapshot-local"
           credentials {
              username "deployer"
              password "xxxx"
           }
          }
     }
}

Which produces

Failed to transfer file: http://iaa44.papyrus.com/artifactory/libs-snapshot-local/com/papyrus/pct/pct/unspecified/pct-unspecified.war. Return code is: 409

Artifactory apparently returns 409 for checksum problems.

Also, what do I have to do to replace ‘-unspecified’ with a snapshot version - is this something that Artifactory does?

First, I would seriously consider buying “Gradle in Action”, its a fantastic book that goes from project inception to continuous delivery and includes this type of information.

The code that works for my webApp is as follows:

publishing{
    publications{
        webApp(MavenPublication){
            artifactId 'myArtifact'
            from components.web
        }
    }
      repositories{
        maven{
            url fullRepoUrl
              credentials {
                username = binaryRepository.username
                password = binaryRepository.password
            }
        }
    }
}
1 Like

Hi Sion, thank you for your reply, and thank you for the book recommendation.

I have added the artifactId (‘pct’) to the webApp, and I have defined a version (‘2.2.1-SNAPSHOT’). My expectation was that gradle could have done this for me using sensible configuration defaults, so I need to deepen my knowledge here.

The console now shows the following, which will now validate with the team today. It’s obviously not quite right, but it’s better than it was. I also need to understand how to publish a non-SNAPSHOT release.

:generatePomFileForMavenWebPublication
:publishMavenWebPublicationToMavenRepository
Uploading: com/papyrus/pct/pct/2.2.1-SNAPSHOT/pct-2.2.1-20140115.071629-1.war to repository remote at http://iaa44.papyrus.com/artifactory/libs-snapshot-local
Transferring 29544K from remote
Uploaded 29544K
:publish

I guess that the problem I had with the 409 code was due to uploading an empty or non-existant pct.war.

Problem I’m facing now is that the war file appears in Artifactory as

  • com/papyrus/pct/pct/2.2.1-SNAPSHOT I would like it to appear as * com.papyrus.pct/pct/2.2.1-SNAPSHOT

The pom.xml file contains the following, which is all correct groupId:com.papyrus.pct artifactId:pct version:2.2.3-SNAPSHOT packaging:war

That’s how a Maven repository organizes the artifacts. Dots in your ‘groupId’ evaluate to individual subdirectories.

Our company standard for Artifactory is com.papyrus.pct/pct, not com/papyrus/pct/pct. I assume the maven publish plugin defaults to com/papyrus/pct/pct/ (this is what I see in the console window : Uploading: com/papyrus/pct/pct/ … …). Do I have to write some code in order to make it upload com.papyrus.pct/pct? I’ve had a brief look at various classes within the gradle distribution, but have not been able to find out where this is controlled.

There is no way to do this for Maven repos. To get this layout, you’ll have to treat Artifactory as an Ivy repo.

I never tried this but you might be able to escape the dots when assigning the publication’s ‘groupId’. Have a look at the section “65.2.3. Identity values in the generated POM” in the user guide.

Hi Peter - I have referenced the Artifactory repository as an Ivy repository, and it works!

Thanks for your help.

/Martin

How did you do that?

apply plugin: ‘ivy-publish’

[…]

publishing {

publications {

ivy(IvyPublication) {

organisation ‘com.papyrus.pct’

from components.web // war file

}

}

repositories {

ivy {

url “http://xxx.papyrus.com/artifactory/libs-snapshot-local

credentials {

username “scott”

password “tiger”

}

}

} }

[…]

Hi Martin,

have you actually managed to upload the .war file under Artifactory? In my case the script gets stuck at 83% and can’t seem to be able to upload the .war.

see my gradle.build extract:

plugins {

id ‘java’

id ‘osgi’

id ‘maven-publish’

id ‘com.jfrog.artifactory’ version ‘3.0.1’

id “fr.javatic.jboss-controller” version “1.3”

id ‘war’ }

repositories {

mavenLocal()

mavenCentral() }

dependencies {

compile group : ‘org.springframework’, name : ‘spring’, version: ‘2.5.6’

compile group : ‘org.springframework’, name : ‘spring-webmvc’, version: ‘2.5.6’

compile group : ‘javax.servlet’, name : ‘jstl’, version: ‘1.1.2’

compile group : ‘taglibs’, name : ‘standard’, version: ‘1.1.2’

compile group : ‘javax.servlet’, name : ‘servlet-api’, version: ‘2.5’

testCompile group: ‘junit’, name: ‘junit’, version: ‘4.11’

}

group = ‘com.mykong.common.controller’ version = ‘1.0’ publishing {

publications {

webApp(MavenPublication){

artifactId ‘SpringMVC’

from components.web

}

}

repositories {

maven {

name ‘remoteArtifactory’

url “${fullRepoUrl}”

credentials {

username = “admin”

password = “welcome1-”

}

}

} }

And this is the output:

[user@localhost SpringMVC]$ gradle publishWebAppPublicationToRemoteArtifactoryRepository [buildinfo] Properties file path was not found! (Relevant only for builds running on a CI Server) Publication named ‘mavenJava’ does not exist for project ‘:’ in task ‘:artifactoryPublish’. None of the specified publications matched for project ‘:’ - nothing to publish. :generatePomFileForWebAppPublication :compileJava UP-TO-DATE :processResources UP-TO-DATE :classes UP-TO-DATE :war UP-TO-DATE :publishWebAppPublicationToRemoteArtifactoryRepository Uploading: com/mykong/common/controller/SpringMVC/1.0/SpringMVC-1.0.war to repository remote at http://54.34.200.88:8081/artifactory/libs-release-local Transferring 4713K from remote

Thanks in advance, Ettore.

Hi Ettore, well, this was a long time ago, but yes, it worked. Sorry, I wouldn’t know how to help with your problem.

/Martin