New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Artifact name and version configured in publication are not used when publishing project dependencies #11299
Comments
If I add multiple
However |
In case you wondered, Gradle 6.0 metadata is wrong as well:
{
"formatVersion": "1.1",
"component": {
"group": "custom-artifacts",
"module": "custom-bom",
"version": "1.1.0",
"attributes": {
"org.gradle.status": "release"
}
},
"createdBy": {
"gradle": {
"version": "6.0",
"buildId": "4in6ac5zknfj5nxjsucbagvii4"
}
},
"variants": [
{
"name": "apiElements",
"attributes": {
"org.gradle.category": "platform",
"org.gradle.usage": "java-api"
}
},
{
"name": "runtimeElements",
"attributes": {
"org.gradle.category": "platform",
"org.gradle.usage": "java-runtime"
},
"dependencyConstraints": [
{
"group": "custom-artifacts",
"module": "core",
"version": {
"requires": "unspecified"
}
}
]
}
]
} |
Since I'd already prepared this https://github.com/bdellegrazie/gradle-java-platform-sample before discovering this bug report, I'll link to it. |
Ideally, it would be great if the fix was also backported to Gradle 5.x (it should be easy, as there has been no changes in the affected code between 5.x and 6.0). Unfortunately we cannot migrate to 6.0 right now because of incompatible changes that make our build fail. |
So it took me a bit to sort through this. :) At first, I think the title of the issue was misleading so I updated it. The following is working (we were thinking that is what this is all about):
If you add a constraint on a project to the platform, it is also working and it is published correctly:
(If in What is NOT working Is if you change the name/version in the publication, it is not reflected when the project dependencies is resolved to coordinates. I am not surprised by that. In fact, I am not convinced anything should be changed here. (Except for maybe giving some kind of warning/errror during publishing instead of publishing something that does not work.) The whole idea of configuring essential parts of the component inside the publication is flawed. It is possible (because it always was), but I think if we are talking about publishing Java projects, the recommendation should be not to use that. Which includes APIs like
Plus maybe some informal metadata like licensing etc. (for which we do not have a better API yet) and some POM manipulation if something "special" needs to be done for Maven consumers. So all parts that make up the identity and interface (i.e. outgoing/published artifacts) should be defined globally for the project or in the "component" that is published (ideally there is only one component per project). So I would like to understand what your use cases are to configure these things in the publication. @bdellegrazie In your example, you could remove the
@vlsi @sergei-ivanov could your issue(s) also be solved like this? If not, can you explain what is missing? Note: I am a bit surprised that #11317 works. Seems like we already take one (the first??) publication into account when resolving a project's coordinates. However, I am (currently) not convinced that we should go down that road further (as explained above). |
@jjohannes I will try your suggestion - thank you. |
@jjohannes , can you please share the project that is "working" for you? I did provide a full-blown example (see custom-artifact.zip in the first message):
|
It would make command-line harder to use. For instance, Apache JMeter artifacts have names like |
@vlsi Regarding #11299 (comment): That is not working, because the artifact name/version is configured in the If the only problem with the solution is the command line, then you can also do something like this in
It's a bit of a hack, but I think it is still better to do it this way around (i.e. not change the identity of the projects). If you want/need to keep the "old" name, the projects should also use that for their identity I would say. Because it is not just a publishing detail. It is the public identity and everyone consuming your published component also needs to continue to use the "old" name. |
I do not follow that :( Do you mean you are going to deprecate and remove https://docs.gradle.org/current/userguide/publishing_maven.html#sec:identity_values_in_the_generated_pom ? If you review DefaultMavenPublication.java and GradleModuleMetadataWriter.java you'll see that both those classes perform extra resolving like the following: https://github.com/gradle/gradle/blob/7c95b1b75edf091b6e63d9c4ab83d655a20f054f/subprojects/maven/src/main/java/org/gradle/api/publish/maven/internal/publication/DefaultMavenPublication.java#L435 However, the resolution via projectDependencyResolver is performed only for regular project dependencies. Having project name != folder name consumes space in IDEA as well (as it starts to show both folder name and actual project name in brackets)
Parsing the command-line does not seem to be fun.
"old" publication was implemented in Apache Ant. Now the project is migrated to Gradle, and artifactId in the publications is there to make the publication names to be exactly the same as they were with Ant. |
We discussed this again internally and since this is working for dependencies, I was convinced that it should also work for constraints. Thanks for your patience and feedback. We will have another look at your PR @vlsi and see that we get it integrated. |
@jjohannes , thank you. I see that "what if a project has multiple publications with all having different ids" is a slippery slope (which is to use when |
fixes gradle#11299 Signed-off-by: Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
Your PR is in for |
@jjohannes any chance it could be backported to 5.4.x please? |
@bdellegrazie We have no concrete plan for another 5.4.x release at the moment. If that should change, we can consider to include this. In the meantime, can you confirm that the fix is working for you (e.g. with the latest nightly Is there anything specific blocking you to move to 6.x? |
Having just wasted two WEEKS trying to get two packages to publish, I finally discovered this obscure comment in a closed issue. Removing the explicit artifactId and version finally allowed me to publish two modules without Gradle failing internally. The artifactId and version are explicitly set in every example everywhere, and every example and shred of documentation implies that they're even mandatory. This issues is not actually complete until you FIX THE DESIGN FLAW and UPDATE THE DOCUMENTATION. Also, please do the obvious thing and introduce publicationArtifactId and publicationVersion as project extension fields that the publication plugin looks for (falling back to the project's name and version if absent). And then remove forever those broken fields from publication. |
Expected Behavior
Gradle should take
artifactId
andversion
fromMavenPublication
when generatingpom.xml
Current Behavior
Gradle uses
version
from project, and it usesproject.name
forartifactId
.Context
This impacts
BOM
generation for ApacheJMeter.Historically, Maven artifacts were named like
ApacheJMeter_core
while the folder layout was justcore
.That is why JMeter uses
artifactId != project.name
inpom.xml
for backward compatibility.Steps to Reproduce
custom-artifact.zip
The test case is to execute (in any order) the following tasks:
:bom:generatePomFileForBomPublication
,:core:generatePomFileForCorePublication
,:lib:generatePomFileForLibPublication
Just in case:
core
:core/.../pom-default.xml
(it is expected):bom
:bom/.../pom-default.xml
:lib
:lib/.../pom-default.xml
(it is OK):Your Environment
Gradle 6.0
The text was updated successfully, but these errors were encountered: