Skip to content

Conversation

jnizet
Copy link
Contributor

@jnizet jnizet commented Oct 3, 2018

This allows simplifying the test build scripts by avoiding to set the classpath in each of them.
It also allows (and requires, as a matter of fact) to use the plugins block to apply the boot plugin
under test.

Unfortunately, this doesn't work for the tests for the reaction to the Kotlin plugin.
See the comments in the GradleBuild class and in each KotlingPluginActionIntegrationTests build script.

See #14585 (comment)

This allows simplifying the test build scripts by avoiding to set the classpath in each of them.
It also allows (and requires, as a matter of fact) to use the plugins block to apply the boot plugin
under test.

Unfortunately, this doesn't work for the tests for the reaction to the Kotlin plugin.
See the comments in the GradleBuild class and in each KotlingPluginActionIntegrationTests build script.
@wilkinsona
Copy link
Member

On first impressions, this looks great. Thank you, @jnizet.

You've obviously done some digging into the oddity with the tests that react to the Kotlin plugin being applied. Did you get a feel for why that plugin in particular gets loaded using a different class loader? There are other tests that cover reacting to other plugins being applied that don't appear to suffer from the same problem. I wonder what's special about the Kotlin plugin.

@jnizet
Copy link
Contributor Author

jnizet commented Oct 3, 2018

Thanks @wilkinsona!

I've asked a question on the Gradle Slack plugin (in the plugin-development channel) this morning, but I'm still waiting for an answer.

As far as I understand, reacting to the built-in pugins isn't a problem because they're in the "built-in" classpath (not sure about the terminology, but hopefully you get the idea).

Reacting to the dependency management plugin is fine because it's bundled with the boot plugin and is thus part of the plugin classpath set on the gradle runner.

The Kotlin plugin is the only one that is part of the compile classpath of the boot plugin, but is not bundled with it, and is loaded dynamically by gradle at runtime. If you look at the implementation of the various PluginApplicationAction subclasses, the Kotlin one is the only one where Class.forName() is used to dynamically load the plugin class (and return null if loading the class fails). For all the other ones, a class literal (e.g. WarPlugin.class) is returned directly.

I guess it would be possible to make the tests pass by using reflection to mutate the plugin and its tasks, but I don't think this is a good idea.

If the Gradle guys provide another workaround or a solution, I'll be happy to amend this PR or open a new one.

@philwebb philwebb added this to the 2.1.x milestone Oct 4, 2018
@philwebb philwebb added type: task A general task and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 4, 2018
wilkinsona pushed a commit that referenced this pull request Oct 4, 2018
Previously, each test build script used a property to configure its
classpath. This commit simplifies the tests by setting the classpath
once on the GradleRunner, thereby removing the need for it to be set in
each test script. It also allows, and, in fact, requires, the use of
the plugins block to apply the Boot plugin under test.

Unfortunately, this doesn't work for the tests for the reaction to the
Kotlin plugin. See the comments in the GradleBuild class and in each
KotlingPluginActionIntegrationTests build script.

See gh-14680
@wilkinsona wilkinsona closed this in 8c6910c Oct 4, 2018
wilkinsona added a commit that referenced this pull request Oct 4, 2018
* gh-14680:
  Polish "Refactor Gradle plugin tests to use runner's plugin classpath"
  Refactor Gradle plugin tests to use runner's plugin classpath
@wilkinsona wilkinsona modified the milestones: 2.1.x, 2.1.0.RC1 Oct 4, 2018
@wilkinsona
Copy link
Member

Thanks for the explanation, @jnizet, and once again for the PR. I've merged the changes into master. I've also tweaked things a bit in 8c6910c to allow the runner's plugin classpath to be used for the Kotlin plugin tests too. It's using the same approach as was already used for the Dependency Management plugin.

@jnizet
Copy link
Contributor Author

jnizet commented Oct 4, 2018

Thanks for letting me know. I was reluctant to do that because it makes the tests run in conditions that are different from the actual runtime conditions, where the Kotlin plugin is not bundled with the Boot plugin.

@wilkinsona
Copy link
Member

The runtime conditions seem to be different to the test conditions with either approach. Given that, I thought it was better to take the approach that keep things consistent in the tests.

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

Successfully merging this pull request may close these issues.

4 participants