I've got a library (Lib1) that depends on several other libraries (Lib2 and Lib3) that I build from source alongside Lib1. All three are published as artifacts, with artifact ids my-artifact-lib1, my-artifact-lib2, and my-artifact-lib3 respectively. When I publish the artifacts via the maven-publish plugin, I wind up with a dependencies element in the pom file like the following:
<dependencies>
<dependency>
<groupId>org.my.group</groupId>
<artifactId>Lib2</artifactId>
<version>unspecified</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.my.group</groupId>
<artifactId>Lib3</artifactId>
<version>unspecified</version>
<scope>runtime</scope>
</dependency>
</dependencies>
The unspecified versions can be fixed by placing a version property in an allprojects{} block in the project level build.gradle, but the bigger problem is that the artifact ids don't match the publish data:
Lib1Publication(MavenPublication) {
from components.release
groupId "org.my.group"
artifactId "my-artifact-lib1"
version "${version_major}.${version_minor}."+getPatchVersion()
}
Lib2Publication(MavenPublication) {
from components.release
groupId "org.my.group"
artifactId "my-artifact-lib2"
version "${version_major}.${version_minor}."+getPatchVersion()
}
Lib3Publication(MavenPublication) {
from components.release
groupId "org.my.group"
artifactId "my-artifact-lib3"
version "${version_major}.${version_minor}."+getPatchVersion()
}
This creates a problem where any client trying to use my-artifact-lib1 as a dependency and requiring my-artifact-lib2 and my-artifact-lib3 as transitive dependencies winds up searching for artifact ids Lib2 and Lib3 instead and finding nothing.
Module level build.gradle of Lib1 with the project dependencies on the other two modules is as follows:
dependencies {
implementation project(path: ':Lib2')
implementation project(path: ':Lib3')
}
How can I get the generated transitive dependencies for my-artifact-lib1 to use the correct artifact ids for project dependencies, rather than their module names?
I have a similar structure and at least for me the following changes work:
I have ensured, that the subproject-name matches exactly the desired final library name. So in your example I have changed the project Lib1 into my-artifact-lib1.
Regarding version and group the solution seems to be, that in the root build.gradle the definition allprojects has to be included like
allprojects {
group "org.my.group"
version "${version_major}.${version_minor}."+getPatchVersion()
}
at least in my environment this works