Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nebula.release plugin cannot be applied to precompiled build script. #236

Open
u6f6o opened this issue Mar 6, 2023 · 1 comment
Open

Comments

@u6f6o
Copy link

u6f6o commented Mar 6, 2023

I am currently working on externalizing common build steps of our projects (e.g. artefact publishing) using precompiled build scripts. In general this approach works fine but as soon as I try to apply the nebula.release plugin, the build fails with the following exception:

> Task :generatePrecompiledScriptPluginAccessors
Git repository not found at /Users/somebody/Projects/git.acme.com/gradle-plugins/build/tmp/generatePrecompiledScriptPluginAccessors/accessors3038685752906344908 -- nebula-release tasks will not be available. Use the git.root Gradle property to specify a different directory.

> Task :compileKotlin FAILED
e: /Users/somebody/Projects/git.acme.com/gradle-plugins/src/main/kotlin/com.acme.publish.gradle.kts: (6, 1): Unresolved reference: nebulaRelease
e: /Users/somebody/Projects/git.acme.com/gradle-plugins/src/main/kotlin/com.acme.publish.gradle.kts: (7, 5): Unresolved reference: addReleaseBranchPattern
e: /Users/somebody/Projects/git.acme.com/gradle-plugins/src/main/kotlin/com.acme.publish.gradle.kts: (40, 1): Expression 'release' cannot be invoked as a function. The function 'invoke()' is not found
e: /Users/somebody/Projects/git.acme.com/gradle-plugins/src/main/kotlin/com.acme.publish.gradle.kts: (40, 1): Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
internal val ComNetflixNebulaPluginGroup.release: PluginDependencySpec defined in gradle.kotlin.dsl.plugins._a06f7d6c83541c827fbf1cfda5baf9c1 in file PluginSpecBuilders.kt
internal val NebulaPluginGroup.release: PluginDependencySpec defined in gradle.kotlin.dsl.plugins._a06f7d6c83541c827fbf1cfda5baf9c1 in file PluginSpecBuilders.kt
e: /Users/somebody/Projects/git.acme.com/gradle-plugins/src/main/kotlin/com.acme.publish.gradle.kts: (40, 11): Unresolved reference: finalizedBy
e: /Users/somebody/Projects/git.acme.com/gradle-plugins/src/main/kotlin/com.acme.publish.gradle.kts: (40, 24): Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
internal val TaskContainer.publish: TaskProvider<DefaultTask> defined in gradle.kotlin.dsl.accessors._b7719bb009bf77985775c5b9fa4e40d9 in file Accessorsb13nju9doius8kxwhlptqirtr.kt

My gradle-plugins/build.gradle.kts looks like the following:

plugins {
    `kotlin-dsl`
    `kotlin-dsl-precompiled-script-plugins`
    `maven-publish`
    id("pl.allegro.tech.build.axion-release") version "1.14.0"
}

repositories {
    mavenCentral()
}

group = "com.acme"
version = scmVersion.version

dependencies {
    implementation("com.netflix.nebula:nebula-release-plugin:17.1.0")
}

publishing {
    repositories {
        maven {
            url = uri("https://git.acme.com/api/v4/projects/1388/packages/maven")
            name = "Acme.com-GitLab"
            credentials(HttpHeaderCredentials::class) {
                name = "Job-Token"
                value = System.getenv("CI_JOB_TOKEN")
            }
            authentication {
                create<HttpHeaderAuthentication>("header")
            }
        }
    }
}

While my precompiled script file gradle-plugins/src/main/kotlin/com.acme.publish.gradle.kts looks like the following:

plugins {
    `maven-publish`
    id("nebula.release")
}

nebulaRelease {
    addReleaseBranchPattern("develop")
}

publishing {
    publications {
        create<MavenPublication>("maven") {
            groupId = "com.acme"
            artifactId = project.name
            from(components["java"])
        }
    }
    repositories {
        maven {
            val repoName = "Acme.com-GitLab"
            val projectId = System.getenv("CI_PROJECT_ID")
            val repoUrl = "https://git.acme.com/api/v4/projects/${projectId}/packages/maven"
            val runsOnCi = System.getenv().containsKey("CI")
            val tokenType = if (runsOnCi) { "Job-Token" } else { "Private-Token" }
            val accessToken = if (runsOnCi) { System.getenv("CI_JOB_TOKEN") } else { System.getenv("GITLAB_API_TOKEN") }

            url = uri(repoUrl)
            name = repoName
            credentials(HttpHeaderCredentials::class) {
                name = tokenType
                value = accessToken
            }
            authentication {
                create<HttpHeaderAuthentication>("header")
            }
        }
    }
}

release { finalizedBy (publish) }

According to a member of the gradle forums, this stems from an incompatibility of nebula.releas with the new way of applying plugins in gradle:

Well, that plugin is obviously not compatible with being applied in the plugins { ... } block of a precompiled script plugin.
You should open a feature request with them.

The plugins { ... } block of a precompiled script plugin is transplanted to a dummy project that is then evaluated and investigated to find out which typesafe accessors for Kotlin DSL should be generated.

But as that plugin does an early-out at nebula-release-plugin/ReleasePlugin.groovy at main · nebula-plugins/nebula-release-plugin · GitHub 1 before any tasks or extensions are added, no typesafe accessors are generated and you only get that warning during the accessor determination step.

To get rid of that warning you would need to apply the plugin the legacy way using apply instead of the plugins { ... } block.
To make your plugin compile and work, you need to use the uglier longer raw version instead of the accessors, so replace nebulaRelease { by configure {.

Would be happy, if I could use the new style of applying gradle plugins also with the nebula plugin.

@u6f6o
Copy link
Author

u6f6o commented Apr 18, 2023

The same (fast exit) happens when testing a regular standalone plugin with gradle TestKit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant