I have a project which has a SharedCode
(Java) module and secondly an Android
(Android library) module which depends on the SharedCode
module. I've previously been using the maven
plugin in my build.gradle
files and I've been using the uploadArchives
task of that plugin to publish the artifacts from my two modules. This has worked and produced pom files which reflect the dependencies in my build.gradle
files.
I thought I'd replace the old maven
plugin with the new maven-publish
plugin. However, I see that the pom files produced by the maven-publish
plugin contain no dependencies. Is this by design, is this a bug in the plugin or am I using the plugin incorrectly?
The build.gradle
file in my SharedCode
module is as follows:
apply plugin: 'java'
apply plugin: 'maven-publish'
group = "${projectGroupId}"
version = "${projectVersionName}"
dependencies {
compile 'com.google.guava:guava:18.0'
}
publishing {
publications {
SharedCode(MavenPublication) {
groupId "${projectGroupId}"
artifactId 'SharedCode'
version "${projectVersionName}"
artifact("$buildDir/libs/SharedCode-${projectVersionName}.jar")
}
}
}
The build.gradle
file in my Android
module is as follows:
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
group = "${projectGroupId}"
version = "${projectVersionName}"
android {
// android stuff here...
}
dependencies {
compile project(':SharedCode')
}
publishing {
publications {
Android(MavenPublication) {
groupId "${projectGroupId}"
artifactId 'Android'
version "${projectVersionName}"
artifact "$buildDir/outputs/aar/Android-release.aar"
}
}
}
The pom file created from the SharedCode
module is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.sdk</groupId>
<artifactId>SharedCode</artifactId>
<version>0.0.2</version>
</project>
The pom file created from the Android
module is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.sdk</groupId>
<artifactId>Android</artifactId>
<version>0.0.2</version>
<packaging>aar</packaging>
</project>
Note the absence of the dependencies in the pom files.
Use from components.java
instead of the artifact...
line in your publications
section for the java project. That should produce the dependencies in the pom automatically.
The android project isn't recognized as a standard java project, which makes it a bit trickier. You can create your own dependencies section using pom.withXml {}
and then iterating through your dependency list. Alternatively, there is this gradle plugin that does it for yout.