-
Notifications
You must be signed in to change notification settings - Fork 431
Static accessor generation not working as expected #1303
Description
Attempting to use a buildSrc plugin in a subproject and the accessors are not being generated.
Expected Behavior
Static accessor generation should work.
Current Behavior
Accessors are not generated and not available on classpath for subprojects, and depending on state of the project can either succeed or fail depending on what accessors have been stored in the Gradle home cache.
Context
In a multi-project build this leads to an incredibly confusing experience that is difficult to figure out. The workaround is to use the dynamic string invocation accessors.
Steps to Reproduce (for bugs)
The expectation below is the subproject :r has task accessors from the "mybuild.my-base" plugin and the root project get's accessors for base and the built-in wrapper task.
-
Setup a Gradle 5.0 project. I did this running inside of a
gradle:5.0.0-jdk8Docker Hub container to make sure everything was clean.$ docker run -it --rm gradle:5.0.0-jdk8 mkdir -p my-project && cd my-project gradle init --type basic --dsl kotlin --project-name my-project -
write root settings file (project name is just reduced from my original project)
cat << EOF > settings.gradle.kts rootProject.name = "my-project" include(":r") EOF -
write
buildSrcbuild filebuildSrc/build.gradle.ktsmkdir -p buildSrc && cat << 'EOF' > buildSrc/build.gradle.kts import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { `kotlin-dsl` } repositories { jcenter() } gradlePlugin { plugins { register("myBase") { id = "mybuild.my-base" implementationClass = "mybuild.MyBasePlugin" } } } EOF -
write plugin file
mkdir -p buildSrc/src/main/kotlin/mybuild/ && cat << EOF > buildSrc/src/main/kotlin/mybuild/MyBasePlugin.kt package mybuild import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.kotlin.dsl.invoke import org.gradle.language.base.plugins.LifecycleBasePlugin class MyBasePlugin : Plugin<Project> { override fun apply(target: Project) { target.run { tasks { register("myBaseTask") { description = "My base task" } } } } } EOF -
write build script for project
:r.mkdir -p r && cat << 'EOF' > r/build.gradle.kts plugins { base mybuild.`my-base` } tasks { // prove accessing a `base` plugin task works assemble { } myBaseTask { doLast { println("my base") } } } EOF -
run
./gradlew- static accessors can be accessed, and build success -
create root build script
build.gradle.ktscat << EOF > build.gradle.kts plugins { base } tasks { wrapper { gradleVersion = "5.0" } assemble { doFirst { println("assembling!") } } } EOF -
run
./gradlew- failure with static accessors> Configure project : e: /home/gradle/my-project/build.gradle.kts:6:3: Expression 'wrapper' cannot be invoked as a function. The function 'invoke()' is not found e: /home/gradle/my-project/build.gradle.kts:6:3: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: public val PluginDependenciesSpec.wrapper: PluginDependencySpec defined in org.gradle.kotlin.dsl e: /home/gradle/my-project/build.gradle.kts:7:5: Unresolved reference: gradleVersion FAILURE: Build failed with an exception. * Where: Build file '/home/gradle/my-project/build.gradle.kts' line: 6 * What went wrong: Script compilation errors: Line 6: wrapper { ^ Expression 'wrapper' cannot be invoked as a function. The function 'invoke()' is not found Line 6: wrapper { ^ Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: public val PluginDependenciesSpec.wrapper: PluginDependencySpec defined in org.gradle.kotlin.dsl Line 7: gradleVersion = "5.0" ^ Unresolved reference: gradleVersion 3 errors * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0. Use '--warning-mode all' to show the individual deprecation warnings. See https://docs.gradle.org/5.0/userguide/command_line_interface.html#sec:command_line_warnings -
remove current caches
rm -rf ~/.gradle/ -
Run
./gradlewagain to see a different build failure> Configure project :r e: /home/gradle/my-project/r/build.gradle.kts:10:3: Unresolved reference: myBaseTask e: /home/gradle/my-project/r/build.gradle.kts:11:5: Unresolved reference: doLast FAILURE: Build failed with an exception. * Where: Build file '/home/gradle/my-project/r/build.gradle.kts' line: 10 * What went wrong: Script compilation errors: Line 10: myBaseTask { ^ Unresolved reference: myBaseTask Line 11: doLast { ^ Unresolved reference: doLast 2 errors * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0. Use '--warning-mode all' to show the individual deprecation warnings. See https://docs.gradle.org/5.0/userguide/command_line_interface.html#sec:command_line_warnings BUILD FAILED in 1m 25s
Your Environment
-
Build scan URL:
-
gradle --version------------------------------------------------------------ Gradle 5.0 ------------------------------------------------------------ Build time: 2018-11-26 11:48:43 UTC Revision: 7fc6e5abf2fc5fe0824aec8a0f5462664dbcd987 Kotlin DSL: 1.0.4 Kotlin: 1.3.10 Groovy: 2.5.4 Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018 JVM: 1.8.0_191 (Oracle Corporation 25.191-b12) OS: Linux 4.15.0-43-generic amd64