Hello gradle community
How can I customize the scope of dependencies in a pom generated by maven-publish? is there any mapping between gradle configurations and maven scopes?
for example I have the following dependendencies in my build.gradle:
what should be the maven scopes in the generated pom in that case for example?
also how I can set the type (zip, jar …etc)?
note that dependency is declared in the generated pom as following :
<dependency>
<groupId>grpId1</groupId>
<artifactId>artId1</artifactId>
<version>version1</version>
<scope>runtime</scope>
<type>zip or jar</type>
</dependency>
There are possibilities, latest by XML manipulation, but it is always a bad idea, especially when also Gradle Module Metadata is published (the default) as by manipulating the POM you would get inconsistent information in the two files and thus inconsistent resolution depending on whether Gradle or some other consumer tool is used.
You should not need to modify scope or type usually.
If you for example want to change the scope from runtime to compile because you use artId1 in your public API (parameter types, return types, superclasses, …) and so downstream projects need it in their compile classpath even if they don’t use those types themselves, then using implementation is wrong, but you should apply the java-library plugin instead and use api.
The type by default is jar which is correct if you depend on the jar.
If you instead depend on the zip artifact of a dependency like with implementation("org.wildfly:wildfly-dist:31.0.1.Final@zip"), then also in the generated POM the type will already be properly set to zip, as well as in the Gradle Module Metadata.
you are right, I should keep the default generated scopes but I just notice while testing the behavior of the scope regarding the gradle configuration the following remarks:
when I put implementation as gradle configuration the generated POM reference a dependency and set scope to runtime which is the expected result.
when I put compileOnly (just for test purpose) configuration the generated POM doesn’t reference the dependency at all…
is there an explanation for that?
Sure, you told it so. compileOnly means only available at compile time.
If you want “optional” dependencies, I recommend you read Optional dependencies are not optional and then use feature variants.