-
-
Save Robyer/a6578e60127418b380ca133a1291f017 to your computer and use it in GitHub Desktop.
// You can use maven-publish-helper.gradle script without changes and even share it between multiple | |
// modules. Just place the maven-publish-helper.gradle file in the root directory of your project, | |
// then apply it at the bottom of your module's build.gradle file like this: | |
// ...content of module's build.gradle file... | |
apply from: '../maven-publish-helper.gradle' | |
publishing { | |
publications { | |
release(MavenPublication) { | |
// Specify own groupId as package name of your library, | |
// otherwise it would just use project's name (=name of the root directory) by default. | |
groupId 'com.example' | |
// Specify custom artifactId if needed, | |
// otherwise it would use module's name by default. | |
//artifactId 'custom-artifact' | |
// You can specify custom version, | |
// otherwise it would use version from `android { defaultConfig { ... } }` by default. | |
//version = '1.0' | |
} | |
} | |
} |
/** | |
* Maven Publish Helper | |
* | |
* Requires Android Gradle plugin 3.6.0 or higher (available since Android Studio 3.6). | |
* See also: https://developer.android.com/studio/build/maven-publish-plugin | |
* | |
* @Author Robert Pösel | |
* @Version 1.5 | |
* @Date 3.3.2020 | |
*/ | |
apply plugin: 'maven-publish' | |
task androidJavadocs(type: Javadoc) { | |
source = android.sourceSets.main.java.srcDirs | |
classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) | |
android.libraryVariants.all { variant -> | |
if (variant.name == 'release') { | |
owner.classpath += variant.javaCompileProvider.get().classpath | |
} | |
} | |
exclude '**/R.html', '**/R.*.html', '**/index.html' | |
} | |
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) { | |
archiveClassifier.set('javadoc') | |
from androidJavadocs.destinationDir | |
} | |
task androidSourcesJar(type: Jar) { | |
archiveClassifier.set('sources') | |
from android.sourceSets.main.java.srcDirs | |
} | |
// Because the components are created only during the afterEvaluate phase, you must | |
// configure your publications using the afterEvaluate() lifecycle method. | |
afterEvaluate { | |
publishing { | |
publications { | |
// Creates a Maven publication called "release". | |
release(MavenPublication) { | |
// Applies the component for the release build variant. | |
from components.release | |
// Adds javadocs and sources as separate jars. | |
artifact androidJavadocsJar | |
artifact androidSourcesJar | |
// You can customize attributes of the publication here or in module's build.gradle file. | |
//groupId = 'com.example' | |
//artifactId = 'custom-artifact' | |
version = android.defaultConfig.versionName // or just '1.0' | |
} | |
} | |
} | |
} |
@Robyer So what's wrong now with what I have?
Look:
https://github.com/AndroidDeveloperLB/ColorPicker/blob/2237cd55a36524c379e033cd0c5205b514ef4f05/library/build.gradle#L26
@AndroidDeveloperLB Hmm, you must probably configure it differently when you are using Kotlin - maybe that's also reason why it worked for you previously. This my gist is for Java projects and I confirm it works as I specified above, but you may need a different approach for Kotlin projects.
Maybe this will help? https://kotlinlang.org/docs/multiplatform-publish-lib.html
Otherwise use StackOverflow instead, someone will definitely help you there.
@Robyer It was Java based, and had gradle and not kts.
I tried kts just to see how to do it, but got back to gradle after seeing it might be the reason to the issues.
@AndroidDeveloperLB I don't know why it worked before in your case, but right now it is supposed to be done as I said in the comment.
This is actually very simple and easy to do when compared to what I had to do in the past (again, I can't see how it could work in your case).