1
votes

We have created GradleMavenPush plugin that performs upload Artifacts (Gradle Android Artifacts, Gradle Java Artifacts and Gradle Kotlin Artifacts) to Maven repositories (JCenter, Maven Central, Corporate staging/snapshot servers and local Maven repositories)

GradleMavenPush plugin itself can't add buildscript dependencies and then apply dokka-android plugin:

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:0.9.17"
    }
}

apply plugin: 'org.jetbrains.dokka-android'

Plugin with id 'org.jetbrains.dokka-android' not found.

Solution from Can a plugin itself add buildscript dependencies and then apply a plugin? also don't work:

apply plugin: 'groovy'

repositories {
    jcenter()
}

dependencies {
    compile gradleApi()
    compile localGroovy()

    compile "org.jetbrains.dokka:dokka-android-gradle-plugin:0.9.17"
}

apply plugin: 'org.jetbrains.dokka-android'

Plugin with id 'org.jetbrains.dokka-android' not found.

Could you provide any help?

2

2 Answers

1
votes

You should transform your nearly 1000 lines of script plugin code into a real binary Gradle plugin. For that binary plugin, you can specify dependencies, which will be resolved whenever your plugin is added as a classpath dependency of a Gradle build script. From there on, you can simply apply the other plugin from your plugin, as the classes of the other plugin will be available to yours.

The link to the Gradle discussion you provided already explains why you have some kind of a chicken or egg problem. The second code example does provide a possible build.gradle file for your plugin project, it cannot be used directly in a script plugin.

0
votes

Solutions above don't work for script gradle plugins (only for binary gradle plugins)

I implemented my own solution for support Dokka in script gradle plugins.

For Android Java/Kotlin Projects:

        task androidDokka(type: Exec) {
            downloadFile('https://jcenter.bintray.com/org/jetbrains/dokka/dokka-fatjar/0.9.17/dokka-fatjar-0.9.17.jar', 'dokka-fatjar.jar')
            def srcDirsNumber = android.sourceSets.main.java.srcDirs.size()
            def classpathNumber = android.getBootClasspath().size()
            def classpath = (classpathNumber > 0) ? android.getBootClasspath()[0] : ''
            def javaAPISpecificationLink = getJavaAPISpecificationLink()
            if (srcDirsNumber > 0) {
                commandLine 'java', '-jar', "$buildDir/download/dokka-fatjar.jar",
                        android.sourceSets.main.java.srcDirs[0],
                        (srcDirsNumber == 2) ? android.sourceSets.main.java.srcDirs[1] : '',
                        (srcDirsNumber == 3) ? android.sourceSets.main.java.srcDirs[2] : '',
                        '-output', "$buildDir/javadoc", '-format', 'javadoc',
                        (classpathNumber > 0) ? '-classpath' : '', (classpathNumber > 0) ? classpath : '',
                        '-links', "https://developer.android.com/reference/^${android.sdkDirectory}/docs/reference/^${javaAPISpecificationLink}"
            } else {
                commandLine 'java', '-jar', "$buildDir/download/dokka-fatjar.jar"
            }
        }

        task androidDokkaJar(type: Jar, dependsOn: androidDokka) {
            classifier = 'javadoc'
            from "$buildDir/javadoc"
        }

For Other Java/Kotlin Projects (not Android):

        task coreDokka(type: Exec) {
            downloadFile('https://jcenter.bintray.com/org/jetbrains/dokka/dokka-fatjar/0.9.17/dokka-fatjar-0.9.17.jar', 'dokka-fatjar.jar')
            def srcDirsNumber = sourceSets.main.java.srcDirs.size()
            def javaAPISpecificationLink = getJavaAPISpecificationLink()
            if (srcDirsNumber > 0) {
                commandLine 'java', '-jar', "$buildDir/download/dokka-fatjar.jar",
                        sourceSets.main.java.srcDirs[0],
                        (srcDirsNumber == 2) ? sourceSets.main.java.srcDirs[1] : '',
                        (srcDirsNumber == 3) ? sourceSets.main.java.srcDirs[2] : '',
                        '-output', "$buildDir/javadoc", '-format', 'javadoc',
                        '-links', "${javaAPISpecificationLink}"
            } else {
                commandLine 'java', '-jar', "$buildDir/download/dokka-fatjar.jar"
            }
        }

        task dokkaJar(type: Jar, dependsOn: coreDokka) {
            classifier = 'javadoc'
            from "$buildDir/javadoc"
        }