I have a library and a Android app using Gradle and Android Studio. I can include the library directly in the project as following
compile project(':library')
Because I don't want to mesh up with library source code, I want to publish the library into local repository so that I can use as
compile 'com.mygroup:library:1.0'
Any advise?
I just found a solution. In the build.gradle of the library project, add this
apply plugin: 'maven'
group = 'com.mygroup'
version = '1.0'
uploadArchives {
repositories {
mavenDeployer {
repository(url: "file://[your local maven path here]")
// or repository(url: mavenLocal().getUrl())
}
}
}
In the project folder, type following command
gradle uploadArchives
Read Publishing artifacts for more information
For an Android Library you should use the Android Gradle-Maven plugin https://github.com/dcendents/android-maven-gradle-plugin:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
}
}
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
Then to publish to your local repository run:
./gradlew install
which will install it in $HOME/.m2/repository. In your app or other project you can then include it by adding mavenLocal()
to your repositories.
Alternatively, if your library is on GitHub then you can simply include it in other projects using JitPack. Then you don't have to run the above command and can just use what's been pushed.
Publish de library on your local maven repository and then on your gradle use
repositories {
mavenLocal()
}
If you have other repositories listed, make sure your mavenLocal appears first.
Docs: section 51.6.4 on https://gradle.org/docs/current/userguide/dependency_management.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With