Following <https://docs.gradle.org/current/usergui...
# community-support
s
Following https://docs.gradle.org/current/userguide/publishing_customization.html#sec:publishing-custom-components, how do I publish a software component to Maven so that there’s only one artifact but it has both ‘compile’ and ‘provided’ dependencies?
t
What do you mean by "but it has both 'compile' and 'provided' dependencies"? (and how are 'provided' dependencies declared in the project?) In other words, what's your goal? and what did you try that didn't work?
(fwiw, I don't think
<scope>provided</scope>
is of real value for a published library; it's mainly useful for declaring some dependencies in a
<packaging>war</packaging>
Maven project; ymmv)
s
This is a non-Java artifact (a zip file) that I am publishing to Maven. I am using a tool (JetBrains MPS) to build this artifact, and I have a configuration for specifying the tool (
configurations.mps
) as well as a configuration for specifying the dependencies of the artifact (
configurations.languageLibs
). I would like the
languageLibs
to be mapped to
compile
dependencies but
mps
to be mapped to
provided
in the generated POM (just for information). So I define a consumable configuration with my artifact (
configurations.languages
) that extends
languageLibs
and use
component.addVariantsFromConfiguration(languages) { mapToMavenScope("compile") }
. But the API doesn't let me specify "use 'compile' for this extended configuration but 'provided' for that one" or something like that. I could adjust the Maven POM directly using
withXml
but I'm trying to understand why things are modeled the way they are. After all, many existing Maven artifacts have both compile and runtime dependencies in the POM while also providing just one artifact. Can I perhaps create an outgoing configuration without an artifact, just with dependencies, and use that one in the component?
v
withXml
is almost always a bad idea, especially if you also publish Gradle Module Metadata, which is the default, as then the information in the two files is different. It is usually always preferable to fix the model, so that the correct result is produced.
To select the maven scope for a configuration you would normally use
mapToMavenScope
, while this might also not fully produce consistent results, not sure.
s
withXml
is almost always a bad idea, especially if you also publish Gradle Module Metadata, which is the default, as then the information in the two files is different. It is usually always preferable to fix the model, so that the correct result is produced.
Yes, hence the question.
To select the maven scope for a configuration you would normally use
mapToMavenScope
, while this might also not fully produce consistent results, not sure.
It’s consistent all right, just not powerful enough, or I’m missing something.
Actually, it looks like
mapToMavenScope
won’t accept ‘provided’, only ‘compile’ or ‘runtime’. Sad.
On the plus side, adding a variant from an outgoing configuration without artifacts, only with dependencies, works fine.
v
Actually, it looks like
mapToMavenScope
won’t accept ‘provided’, only ‘compile’ or ‘runtime’. Sad.
Oh, sorry, forgot about that as I very rarely used that functionality, but you are right and it is as designed: https://github.com/gradle/gradle/issues/14934