Skip to content
This repository has been archived by the owner on Aug 19, 2020. It is now read-only.

Unable to apply plugins from an applied build script file #179

Closed
tadaskay opened this issue Nov 17, 2016 · 6 comments
Closed

Unable to apply plugins from an applied build script file #179

tadaskay opened this issue Nov 17, 2016 · 6 comments

Comments

@tadaskay
Copy link

tadaskay commented Nov 17, 2016

I have created a small sample project: https://github.com/tadaskay/issues/tree/master/gradle-script-kotlin-apply-from-plugin

It's not possible to apply<HelloWorldPlugin>() from an applied script (applyFrom("applied.gradle.kts") in build.gradle.kts)

Error: Unresolved reference: HelloWorldPlugin (/Users/tadaskay/prj/issues/gradle-script-kotlin-apply-from-plugin/applied.gradle.kts (1:26))
Error: Unresolved reference: HelloWorldPlugin (/Users/tadaskay/prj/issues/gradle-script-kotlin-apply-from-plugin/applied.gradle.kts (3:7))

BTW if you use apply { plugin("...") } syntax, it seems to work for applying plugin itself, but then you have the same problem when you try to configure the extension classes in the applied script.

@oehme
Copy link

oehme commented Nov 17, 2016

This is a known limitation of Gradle, not specific to Kotlin. This can only be solved by supporting script plugins in the new plugins DSL.

You only have a binary choice at the moment: Put everything related to the HelloPlugin into the project script or put everything related to the HelloPlugin in the script plugin (including the buildscript block). You cannot mix both at the moment.

@tadaskay
Copy link
Author

Would you be so kind to provide a link for more information regarding this gradle issue?

I guess it's due to dynamic (default) nature of groovy but it seamlessly worked in my groovy/gradle projects before. Use case looks rather common to me - creating modular build scripts for all aspects of a project (e.g. versioning) by applying relevant plugins and configuring them in related build script files.

Now regarding the second choice, do you mean that I should create a plugin in buildSrc that wraps all the necessary configuration and then apply it in project's main build script? Because moving all the configuration (including the buildscript block) to applied.gradle.kts doesn't work for me either.

@oehme
Copy link

oehme commented Nov 17, 2016

Would you be so kind to provide a link for more information regarding this gradle issue?

The classloaders of each script are isolated from each other. The script plugin cannot see your project's classpath and the project cannot see the script plugin's classpath.

What we want to allow in the future is to make dependencies and classes of the script plugin available to your project's buildscript. This will put script plugins on par with "normal" plugins.

I guess it's due to dynamic (default) nature of groovy but it seamlessly worked in my groovy/gradle projects before. Use case looks rather common to me - creating modular build scripts for all aspects of a project (e.g. versioning) by applying relevant plugins and configuring them in related build script files.

Correct, this only works because of Groovy's dynamic nature. Try referring to an explicit type and you'll see that it fails just like in the Kotlin sample.

Now regarding the second choice, do you mean that I should create a plugin in buildSrc that wraps all the necessary configuration and then apply it in project's main build script? Because moving all the configuration (including the buildscript block) to applied.gradle.kts doesn't work for me either.

I meant to put everything related to HelloPlugin in applied.gradle.kts. If that doesn't work, it would be an issue in gradle-script-kotlin, because it does work for Groovy build scripts.

@tadaskay
Copy link
Author

Thank you for taking the time to explain.

I meant to put everything related to HelloPlugin in applied.gradle.kts. If that doesn't work, it would be an issue in gradle-script-kotlin, because it does work for Groovy build scripts.

I have update the sample project and indeed, after moving everything (except for the applyFrom) to the applied.gradle.kts doesn't work either, so I guess it is a bug after all (a slightly different one).

@bamboo
Copy link
Member

bamboo commented Nov 18, 2016

Hi @tadaskay, buildscript blocks in script plugins are currently not processed.

This feature is planned though: #180.

Thanks for the report!

@bamboo
Copy link
Member

bamboo commented Jan 17, 2018

Superseded by #180.

@bamboo bamboo closed this as completed Jan 17, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants