apply plugin: 'java'
group = 'com.example'
version = '1.0'
jar {
classifier = 'myClassifier'
}
uploadArchives {
repositories {
ivy {
url 'c:/temp/local'
ivyPattern "[organisation]/[module]/[revision]/[artifact](-[classifier])-[revision](.[ext])"
artifactPattern "[organisation]/[module]/[revision]/[artifact](-[classifier])-[revision](.[ext])"
}
}
}
When I run the uploadArchives task with -i, I get this output:
...
:: loading settings :: url = jar:file:/C:/dev/gradle/gradle-1.1/lib/ivy-2.2.0.jar!/org/apache/ivy/core/settings/ivysettings.xml
Published projectA to C:\temp\local/com.example/projectA/1.0/projectA-1.0-myClassifier.jar
Published ivy to C:\temp\local/com.example/projectA/1.0/ivy-1.0.xml
You can see the published artifact does not follow the pattern I specified. The classifier should be between the artifact name and the revision number, but it’s appended at the end per the default archiveName.
I was able to work around it by accessing the API directly:
That publishes the artifacts in the pattern specified:
:: loading settings :: url = jar:file:/C:/dev/gradle/gradle-1.1/lib/ivy-2.2.0.jar!/org/apache/ivy/core/settings/ivysettings.xml
published projectA to c:/temp/local/com.example/projectA/1.0/projectA-myClassifier-1.0.jar
published ivy to c:/temp/local/com.example/projectA/1.0/ivy-1.0.xml
Should this be the case? If so, what is the point of the artifactPattern method on the IvyArtifactRepository class?
Your repositories section needs to be moved outside of your uploadArchives configuration - I am guessing your artifactPattern doesn’t know about your jar {} classifier in the current setup. Try:
apply plugin: 'java'
group = 'com.example'
version = '1.0'
repositories {
ivy {
url 'c:/temp/local'
ivyPattern "[organisation]/[module]/[revision]/[artifact](-[classifier])-[revision](.[ext])"
artifactPattern "[organisation]/[module]/[revision]/[artifact](-[classifier])-[revision](.[ext])"
}
}
jar {
classifier = 'myClassifier'
}
If a multi-project, wrap (at least) the ivy block in an allprojects block if necessary…
Andrew, I could be wrong, but per the Gradle docs I think relocating the repositories section outside the uploadArchives configuration simply configures that as a repo from which artifacts can be downloaded. I believe repos for uploading must be specified as in my example.
When I run your example, nothing gets uploaded at all.
:uploadArchives
Task ':uploadArchives' has not declared any outputs, assuming that it is out-of-date.
Publishing configuration: configuration ':archives'
The problem is how you’re configuring your repository. There are a few things coming into play here:
The first thing you need to know is that Gradle will use the first pattern specified for publishing. 2. Specifying a ‘url’ for your repository tells Gradle to apply the repository layout to the supplied URL. Since you’re not defining a ‘layout’ for your repository, Gradle is applying the default ‘gradle’ layout. 3. Specifying ‘ivyPattern’ or ‘artifactPattern’ for a repository adds an additional pattern. These patterns are not resolved relative to the ‘url’ parameter: unqualified patterns will be resolved like any other file path in Gradle, relative to the project base directory.
So the way you are configuring your repository, you are getting the following effective patterns:
// The default gradle layout applied to the URL provided
ivyPattern "c:/temp/local/[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier])(.[ext])"
artifactPattern "c:/temp/local/[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier])(.[ext])"
// The explicit patterns resolved against project base directory
ivyPattern "${project.projectDir}/[organisation]/[module]/[revision]/[artifact](-[classifier])-[revision](.[ext])"
artifactPattern "${project.projectDir}/[organisation]/[module]/[revision]/[artifact](-[classifier])-[revision](.[ext])"
There are 2 ways to achieve what you want. The simplest is probably to simply omit the repository ‘url’ parameter and supply the fully qualified ‘ivyPattern’ and ‘artifactPattern’ values you want.
Ah, I see. It actually makes sense because we were originally passing a closure to the layout method (as in your 2nd example), and later switched to call artifactPattern directly.
Definitely some improvement in the documentation would be helpful. I think even the Javadoc doesn’t make this distinction clear enough. I’m willing to take a crack at it … I’ve never submitted a patch before, though, documentation or otherwise. Can you point me in the right direction?
Basically, you just fork the gradle project on github, make your changes and submit a pull request. You should be able to find lots of online resources to help with that part.
Ok, I took a shot at it and submitted a pull request (I used some of your answer in this thread).
FYI, one correction to what you said: when uploading, Gradle doesn’t take the first pattern for uploading. It will use ‘url’ if it exists, and use ‘ivyPattern’ and ‘artifiactPattern’ second. So for example: