Today I was able to upload a jar + sources for a simple test project to a maven repo. I just had to create a task which created the sources jar and add that archive in the artifacts section, like so:
artifacts {
archives jar
archives sourcesJar
}
The uploadArchives section doesn’t have anything special. Just the repo configuration.
In my real project I have an ant file that creates all jars (4 in total): A.jar, B.jar and sources for each. I’m currently able to upload both A and B with: https://gist.github.com/4688748
Now I’m trying to attach the sources by doing the same as my test project. Adding two more archives to my artifacts section which point to the sources, but no luck, they seem to go ignored and if I add more filters then they are uploaded as a separate artifact not as the sources.
The only thing that comes to mind to get the job done is to have 2 different configurations, with one artifact + source per configuration but I wouldn’t want to go that way. Is there any way do it with just the archive configuration?
Do the different jars (code and source pairs) have different groups and/or names? In the maven model (I’m assuming you’re publishing to an m2 repo) you cannot have more than one artifact sharing what it terms “coordinates”.
I’d have to see more of your code to provide further help.
As I was preparing the Gist to share it with you, I tried a couple of different things I thought of and finally found the solution. I’m posting it here just in case anyone arrives here with a similar problem.
My problem was that I was adding the archives like this:
What went wrong: Execution failed for task ‘:install’. > Could not publish configuration ‘archives’
A POM cannot have multiple artifacts with the same type and classifier. Already have MavenArtifact my:jar:jar:null, trying to add MavenArtifact my:jar:jar:null.
My env:
Gradle 2.2.1
Build time:
2014-11-24 09:45:35 UTC Build number: none Revision:
6fcb59c06f43a4e6b1bcb401f7686a8601a1fb4a
Groovy:
2.3.6 Ant:
Apache Ant™ version 1.9.3 compiled on December 23 2013 JVM:
If you can’t get this to work with the ‘maven’ plugin (there should be a way), you could try to switch to the ‘maven-publish’ plugin, for which there is a ‘samples/maven-publish/multiple-publications’ sample in the ‘gradle-all’ download. Another option would be to create an additional configuration for the second artifact (which will give you an additional ‘upload’ task), rather than adding both artifacts to the same configuration and using ‘addFilter’ to tear them apart.
That’s the main problem - We cannot use the maven-publish plugin.There are some colateral impacts on our deply systems Therefore I tried to use the solution above, which I found in many flavours all over the net. However, most of the solutions are written 2 years back. I’ll try to create multiple configs in the projects. In the meanwhile I hope someone will look into this issue. Thanks for idea.
I’ve tried your approach as well., it’s just another way of specifying the name of the artifact, which in my case doesn’t work. The working solution was to specify each of the jars as the separate gradle sub-project. Nevertheless, I’m still trying to make it work in the way the Alejandro Salas solved it.