I have a gradle project A
, which I want to export as a library, now I used maven publish plugin to generate pom.xml from its build.gradle
. And successfully uploaded to local artifactory.
Now I am able to import it in another project, but the dependencies are not being considered.
For example: My library A
has dependencies B
and C
. When I use A
in a project, it doesn't download B
and C
.
I am assuming I did something wrong in generating A
(not proper pom.xml
/ or any other mistake).
But I want to know, how does Maven, figures transitive dependencies. Like, which files/locations it scans, where it looks for dependencies?
Code
Task for generating pom.xml
in project A
.
task writeNewPom << {
pom {
project {
groupId 'com.a.b'
version '1.0.0'
}
}.writeTo("src/main/resources/META-INF/maven/com.a.b/feature-store-lib/pom.xml")
}
The location of my pom.xml is in META-INF/maven/com.ab/feature-store-lib/
I am successfully able to upload in artifactory.
I am able to import properly in another gradle project as well, but its transitive dependencies are missing.
Here is the cropped output of gradle dependencies
| | \--- org.junit.platform:junit-platform-commons:1.3.1 (*)
| \--- junit:junit:4.12
| \--- org.hamcrest:hamcrest-core:1.3
+--- com.a.b:feature-store-lib:0.4
+--- io.github.microutils:kotlin-logging:1.6.22
| +--- io.github.microutils:kotlin-logging-common:1.6.22
As you can see there is no trasnitive dependencies coming from com.ab:feature-store-lib:0.4
Need ideas to debug.
First of all I'm going to assume that you are producing a pom this way because of some external requirements. Otherwise I would suggest using the publishing plugin as described in the documentation . Publishing to artifactory becomes very easy this way.
My first instinct is that you might have used the wrong configuration in your dependency declaration. If you are using a newer version of gradle you should be using the api configuration for dependencies that need to be exposed to any user of your artifact.
dependencies {
api 'org.apache.httpcomponents:httpclient:4.5.7' // Exposed
implementation 'org.apache.commons:commons-lang3:3.5' // Not exposed
}
For more information I refer to the gradle documentation on this subject: https://docs.gradle.org/current/userguide/java_library_plugin.html#sec:java_library_configurations_graph
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.