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

Make types from classpath contributed by init scripts available to Kotlin build scripts #9284

Closed
bamboo opened this issue Sep 29, 2016 · 8 comments
Labels

Comments

@bamboo
Copy link
Member

bamboo commented Sep 29, 2016

For instance:

// ~/.gradle/init.d/buildScan.gradle
initscript {
  repositories {
    maven { url = uri("https://plugins.gradle.org/m2") }
  }
  dependencies {
    classpath("com.gradle:build-scan-plugin:1.7.1")
  }
}
@wolfs
Copy link
Member

wolfs commented Jul 10, 2017

When importing a project in intellij when I apply the build scan plugin from an init script like this:

initscript {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2"
        }
    }
    dependencies {
        classpath "com.gradle:build-scan-plugin:1.8"
    }
}
rootProject { prj ->
    apply plugin: initscript.classLoader.loadClass("com.gradle.scan.plugin.BuildScanPlugin")
    buildScan {
        publishAlways()
    }
}

I get the following error in IDEA:

Error:Failed to compile accessors
    projectSchema: ProjectSchema(extensions={ext=org.gradle.api.plugins.ExtraPropertiesExtension, buildScan=com.gradle.scan.plugin.internal.api.f}, conventions={}, configurations=[])
    classPath: [/Users/wolfs/.gradle/caches/4.1-20170707032407+0000/generated-gradle-jars/gradle-api-4.1-20170707032407+0000.jar, /Users/wolfs/.gradle/wrapper/dists/gradle-kotlin-dsl-4.1-20170707032407+0000-all/d3mj6o6gozo0alzok0r3j1q50/gradle-4.1-20170707032407+0000/lib/groovy-all-2.4.11.jar, /Users/wolfs/.gradle/wrapper/dists/gradle-kotlin-dsl-4.1-20170707032407+0000-all/d3mj6o6gozo0alzok0r3j1q50/gradle-4.1-20170707032407+0000/lib/gradle-installation-beacon-4.1.jar, /Users/wolfs/.gradle/caches/4.1-20170707032407+0000/generated-gradle-jars/gradle-kotlin-dsl-extensions-0.10.0-SNAPSHOT-4.1-20170707032407+0000.jar, /Users/wolfs/.gradle/wrapper/dists/gradle-kotlin-dsl-4.1-20170707032407+0000-all/d3mj6o6gozo0alzok0r3j1q50/gradle-4.1-20170707032407+0000/lib/gradle-kotlin-dsl-0.10.0-SNAPSHOT.jar, /Users/wolfs/.gradle/wrapper/dists/gradle-kotlin-dsl-4.1-20170707032407+0000-all/d3mj6o6gozo0alzok0r3j1q50/gradle-4.1-20170707032407+0000/lib/gradle-kotlin-dsl-compiler-plugin-0.10.0-SNAPSHOT.jar, /Users/wolfs/.gradle/wrapper/dists/gradle-kotlin-dsl-4.1-20170707032407+0000-all/d3mj6o6gozo0alzok0r3j1q50/gradle-4.1-20170707032407+0000/lib/gradle-kotlin-dsl-tooling-models-0.10.0-SNAPSHOT.jar, /Users/wolfs/.gradle/wrapper/dists/gradle-kotlin-dsl-4.1-20170707032407+0000-all/d3mj6o6gozo0alzok0r3j1q50/gradle-4.1-20170707032407+0000/lib/kotlin-reflect-1.1.3-2.jar, /Users/wolfs/.gradle/wrapper/dists/gradle-kotlin-dsl-4.1-20170707032407+0000-all/d3mj6o6gozo0alzok0r3j1q50/gradle-4.1-20170707032407+0000/lib/kotlin-stdlib-1.1.3-2.jar]

I would expect this to work or at least give me a better error message what I should do.

@bamboo
Copy link
Member Author

bamboo commented Jul 10, 2017

Blocked by gradle/kotlin-dsl-samples#416.

@bamboo
Copy link
Member Author

bamboo commented Jul 11, 2017

Just to explain the behaviour reported here, the latest release provides extension accessors by default. This requires the types of all extensions to be visible in the build script classpath but currently initscript dependencies are not thus the type of the buildScan extension is not visible and compilation fails.

This behaviour can be disabled via a Gradle project property:

org.gradle.kotlin.dsl.accessors=off

@pioterj
Copy link
Member

pioterj commented Jul 17, 2017

I'm using the following init.d script to enable build scans in all my builds:

initscript {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2"
        }
    }
    dependencies {
        classpath "com.gradle:build-scan-plugin:1.8"
    }
}

rootProject {
    apply plugin: com.gradle.scan.plugin.BuildScanPlugin
    buildScan {
        publishAlways()
        if (project.hasProperty("useProdScanServer")) {
            licenseAgreementUrl = "https://gradle.com/terms-of-service"
            licenseAgree = "yes"
        } else {
            server = "https://internal.gradle.enterprise.server"
        }
    }
}

Importing official Kotlin DSL samples to IDEA results in the following error:

Error:The build scan plugin must be applied early in the build lifecycle.
Fixing this problem requires changing how you are applying the build scan plugin to your build.
Please see https://gradle.com/scans/help/plugin-late-apply for how to resolve this problem.

@bamboo
Copy link
Member Author

bamboo commented Jul 17, 2017

@pioterj, I get the same error with a Groovy based build script so there's something else going on here.

@bamboo
Copy link
Member Author

bamboo commented Jul 17, 2017

The following project reproduces the issue with a Groovy build script on the latest 4.1 nightly:

@bamboo bamboo changed the title Make sure ~./gradle/init.d scripts are executed and changes to the buildscript classpath are taken into account Make types from classpath contributed by init scripts available to Kotlin build scripts Jan 16, 2018
@eskatos eskatos transferred this issue from gradle/kotlin-dsl-samples Apr 25, 2019
@stale
Copy link

stale bot commented Oct 6, 2020

This issue has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be automatically closed if no further activity occurs. If you're interested in how we try to keep the backlog in a healthy state, please read our blog post on how we refine our backlog. If you feel this is something you could contribute, please have a look at our Contributor Guide. Thank you for your contribution.

@stale stale bot added the stale label Oct 6, 2020
@stale
Copy link

stale bot commented Oct 27, 2020

This issue has been automatically closed due to inactivity. If you can reproduce this on a recent version of Gradle or if you have a good use case for this feature, please feel free to reopen the issue with steps to reproduce, a quick explanation of your use case or a high-quality pull request.

@stale stale bot closed this as completed Oct 27, 2020
@wolfs wolfs closed this as not planned Won't fix, can't repro, duplicate, stale Sep 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants