'Is it possible to publish multiple android libraries to the same package on github using the maven-plugin? then import the libraries together or alone
I'm trying to publish multiple libraries to github from the same project in android using the maven-publish plugin. I'm trying to make it so that a person can either consume the whole project with all the libraries eg import com.example.libraries; or import it as single modules such as import com.example.libraries.lib1, import com.example.libraries.lib2 and so on. However, I am unable to do so. Is this possible using Github and if so, how can one go about it?
//build.gradle for lib1
publications {
maven(MavenPublication) {
groupId "com.github.example.libraries"
artifactId "lib1"
version System.getProperty("version")
artifact "/build/outputs/aar/lib1-release.aar"
}
//build.gradle for lib2
publications {
maven(MavenPublication) {
groupId "com.github.example.libraries"
artifactId "lib2"
version System.getProperty("version")
artifact "/build/outputs/aar/lib2-release.aar"
}
Solution 1:[1]
I came up with a solution for a similar problem using flavors.
However, if you have lib1 and lib2 in different modules your solution should work by using the maven-publish plugin in each build.gradle file.
First, declare as many flavors as you need:
flavorDimensions "libs"
productFlavors {
lib1 {
dimension "libs"
}
lib2 {
dimension "libs"
}
}
Then you can use sourceSets to specify the sources for your flavors:
sourceSets {
main {
java {
java.srcDirs = ['src/main/java']
}
res {
srcDirs = ['src/main/res']
}
}
lib1 {
java {
java.srcDirs = ['src/main/java', 'src/lib1/java']
}
}
lib2 {
java {
java.srcDirs = ['src/main/java', 'src/lib2/java']
}
}
}
At the end, you can publish both libraries using maven-publish plugin:
publishing {
publications {
lib1(MavenPublication) {
groupId "com.github.example.libraries"
artifactId "lib2"
version System.getProperty("version")
artifact("/build/outputs/aar/lib2-release.aar") {
extension 'aar'
}
}
lib2(MavenPublication) {
groupId "com.github.example.libraries"
artifactId "lib2"
version System.getProperty("version")
artifact("/build/outputs/aar/lib2-release.aar") {
extension 'aar'
}
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
