Closed alixwar closed 4 years ago
Of course, it is supported. You have to define javadocsJar task with dokka or javadoc task and have to add to artifacts
publications {
mavenAar(MavenPublication) {
from components.android
artifact LazyPublishArtifact(javadocsJar)
artifact LazyPublishArtifact(sourcesJar)
}
}
@warnyul Thanks for the quick reply!
Note: We use Gradle 5.2.1
We have a specific case that I will try to explain which makes this problematic. We want to upload both snapshot versions and release versions (depending on which branch the CI script is running. Our build script applies different configs depending on whether the build is of variant DEBUG och RELEASE. Using your approach, we noticed, leads to the artfacts always applying the RELEASE config.
This is what I mean by DEBUG/RELEASE configs:
buildTypes {
release {
debuggable false
buildConfigField("String", "ANALYTICS_TOKEN", "\"token A\"")
}
debug {
debuggable true
buildConfigField("String", "ANALYTICS_TOKEN", "\"token B\"")
}
}
This is our conf that works for us (but it doesn't upload the javadoc):
publications {
android.libraryVariants.all { variant ->
"maven${variant.name.capitalize()}Aar"(MavenPublication) {
from components.findByName("android${variant.name.capitalize()}")
groupId project.group
artifactId 'parent-project-' + project.name
version project.version
}
}
}
This is what we do for our master branch:
gradlew --no-daemon -PmavenUser=$NEXUS_USER -PmavenPassword=$NEXUS_PASSWORD publishMavenReleaseAarPublicationToMavenRepository
This for our development branch:
gradlew --no-daemon -PmavenUser=$NEXUS_USER -PmavenPassword=$NEXUS_PASSWORD publishMavenDebugAarPublicationToMavenRepository
@alixwar - You'd just take this section from waryul's comment and add it to your own:
artifact LazyPublishArtifact(javadocsJar)
artifact LazyPublishArtifact(sourcesJar)
So it'd come out as something like this:
publications {
android.libraryVariants.all { variant ->
"maven${variant.name.capitalize()}Aar"(MavenPublication) {
from components.findByName("android${variant.name.capitalize()}")
groupId project.group
artifactId 'parent-project-' + project.name
version project.version
artifact LazyPublishArtifact(javadocsJar)
artifact LazyPublishArtifact(sourcesJar)
}
}
}
@Nunnery that doesn't work
org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: Could not find method LazyPublishArtifact() for arguments [task ':core:javadocJar'] on object of type org.gradle.api.publish.maven.internal.publication.DefaultMavenPublication.
Note: These are the tasks that I have defined:
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
options.addStringOption('encoding', 'UTF-8')
options.addStringOption('charSet', 'UTF-8')
}
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
// https://discuss.gradle.org/t/how-does-property-class-work-in-build-configuration/30320
archiveClassifier = 'sources'
}
task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}
task javadocJar(type: Jar, dependsOn: javadoc) {
from javadoc.destinationDir
// https://discuss.gradle.org/t/how-does-property-class-work-in-build-configuration/30320
archiveClassifier = 'javadoc'
}
artifacts {
archives javadocJar
archives sourcesJar
}
Then remove the LazyArtifactPublish
wrapper or add the import for it.
On Fri, Mar 29, 2019, 12:25 PM Alix notifications@github.com wrote:
@Nunnery https://github.com/Nunnery that doesn't work
org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: Could not find method LazyPublishArtifact() for arguments [task ':core:javadocJar'] on object of type org.gradle.api.publish.maven.internal.publication.DefaultMavenPublication.
Note: These are the tasks that I have defined:
tasks.withType(Javadoc) { options.addStringOption('Xdoclint:none', '-quiet') options.addStringOption('encoding', 'UTF-8') options.addStringOption('charSet', 'UTF-8') }
task sourcesJar(type: Jar) { from android.sourceSets.main.java.srcDirs // https://discuss.gradle.org/t/how-does-property-class-work-in-build-configuration/30320 archiveClassifier = 'sources' }
task javadoc(type: Javadoc) { source = android.sourceSets.main.java.srcDirs classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) }
task javadocJar(type: Jar, dependsOn: javadoc) { from javadoc.destinationDir // https://discuss.gradle.org/t/how-does-property-class-work-in-build-configuration/30320 archiveClassifier = 'javadoc' }
artifacts { archives javadocJar archives sourcesJar }
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/wupdigital/android-maven-publish/issues/35#issuecomment-478062013, or mute the thread https://github.com/notifications/unsubscribe-auth/ABmGUtBIx6KwDraNrTQgJhucJVf3Za4hks5vbj6VgaJpZM4cSQsQ .
@Nunnery I'm not sure that I understand what you mean by removing LazyArtifactPublish
wrapper. Then it's exactly as before (doesn't work). Also, adding an import statement doesn't work. The IDE thinks it's completely redundant:
import org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact
publications {
android.libraryVariants.all { variant ->
"maven${variant.name.capitalize()}Aar"(MavenPublication) {
afterEvaluate {
from components.findByName("android${variant.name.capitalize()}")
groupId project.group
artifactId 'parent-project-' + project.name
version project.version
artifact LazyPublishArtifact(javadocJar)
artifact LazyPublishArtifact(sourcesJar)
}
}
}
}
For anyone who stumbles on this issue later, the following worked for me (for uploading sources to Maven):
task sourcesJar(type: Jar) {
from sourceSets.main.allSource
classifier = 'sources'
}
publishing {
repositories {
maven {
name = "..."
url = "..."
credentials {
username = "..."
password = "..."
}
}
}
publications {
mavenJar(MavenPublication) {
from components.kotlin
artifact sourcesJar
version = "..."
}
}
}
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
publishing {
repositories {
maven {
name = "..."
url = "..."
credentials {
username = "..."
password = "..."
}
}
}
publications {
mavenAar(MavenPublication) {
from components.android
artifact sourcesJar
version = "..."
}
}
}
Is the case of publishing Android libraries and its javadoc supported?