Maven Publishing (new) - Custom artifacts


(pointer.on) #1

Hello there,

I’ve been trying to publish and download a custom artifact since two days. As repository software I use Archiva from Apache (http://archiva.apache.org/index.cgi).

The idea is to publish a full and shrinked database-dump. Both as Snapshots. For each task-call, the dependency should be updated.

If I follow the userguide (http://www.gradle.org/docs/current/userguide/publishing_maven.html), and publish a Java Jar, all works fine.

With a custom artifact I get the Jar only if I remove the packaging from the pom-file. But only for the first checkout.

Any further try it doesnt download a new jar. Gradle just shows me the local place of the file (path to the Gradle-Cache).

If I dont prepare the POM-File Gradle download the pom (without the jar)… and thats it. Every retry ends in a “empty” ouput.

Command: gradle testit --refresh-dependencies My EndUserScript:

apply plugin: 'maven'
apply plugin: 'java'
  repositories {
    maven {
     credentials {
            username 'xxx'
            password 'xxx'
        }
        url "xxx/archiva/repository/snapshots"
    }
}
  configurations {
 downloadArchives
}
configurations.all {
   resolutionStrategy.cacheChangingModulesFor 1, 'seconds'
   resolutionStrategy.cacheDynamicVersionsFor 1, 'seconds'
}
  dependencies {
 downloadArchives group: 'de.fitz.dumps', name: 'shrinkedDump', version: '1.0-SNAPSHOT'
}
    task testit << {
 configurations.downloadArchives.each { File file -> println file.path }
}

My PublishScript

apply plugin: 'java'
apply plugin: 'maven-publish'
    task sourceJar(type: Jar) {
    from '.'
    include '*.txt'
}
  publishing {
 repositories {
  maven {
   url "xxx/archiva/repository/snapshots/"
   credentials {
     username = "xxx";
    password = "xxx";
   }
  }
 }
    publications {
  shrinkedDumpPublication(MavenPublication) {
   groupId = 'de.fitz.dumps'
   artifactId = 'shrinkedDump'
   version = '1.0-SNAPSHOT'
   /*artifact sourceJar {
    classifier "text"
    extension "jar"
   }*/
            //from components.java
            artifact source: 'README.txt', classifier: 'text', extension: 'txt'
   pom.withXml {
    asNode().remove(asNode().get("packaging"));
        }
  }
     }
}

#2

Apologies for the delayed reply.

You’re likely hitting different issues here: in resolution and in publishing.

With a maven repository, Gradle will always try to download ‘module-name.jar’ unless:

  1. the packaging is set to something other than ‘jar’ or

  2. the dependency has a classifier mentioned.

To work out why Gradle isn’t downloading the updated snapshot artifacts, you should try updating the published artifact manually and see if that helps. Gradle won’t download an artifact if it hasn’t changed in the repository, if the .sha1 hash of the file hasn’t changed, or if the size+modification-date hasn’t changed.

Let me know if you’re still struggling with this.