jendrik
(Jendrik Johannes)
September 30, 2016, 3:13pm
12
@Andy_Wilkinson I have been looking into the compatibility problem that concerns using ProjectBuilder
for plugin testing:
https://discuss.gradle.org/t/cannot-apply-spring-boot-gradle-plugin-in-own-plugin-with-gradle-3-0
[#GRADLE-3558] Applying a plugin built with Gradle 2.x through ProjectBuilder can't find internal classes
It is now fixed for Gradle 3.2. I am not sure from the conversation if that is the major concern for you or only one of many. But if you think this might solve some of your issue already, I would encourage you to try it out by running the corresponding tests with our latest nightly . If you have feedback, we can put further effort into improving this for 3.2. And if you have other concrete issues with reproducible examples, which are not covered by this, please share them.
committed 09:04AM - 28 Sep 16 UTC
The code that generates these empty interfaces, to ensure compatibility
of plugi… ns compiled with Gradle 2.x in 3.x, is now used to inject these
interfaces into the system class loader during ProjectBuilder
initialisation. In addition, an integration test is added that
demonstrates how to work around the issue in Gradle 3.0 and 3.1
(as this fix will be part of 3.2).
This allows users to write plugin tests with ProjectBuilder covering the
cross-version support scenario. The behaviour of a real Gradle run,
where the injection happens in the class loader hierarchy, can only be
mimicked by this. This is because, in such test scenarios, the
ProjectBuilder runs in a plain Java application with a flat class loader.
+review REVIEW-6246
The test that is part of the fix also contains a workaround to make the project builder tests work with 3.0 / 3.1 if that is a concern for you:
"""
then:
createGradleExecutor(PROJECT_BUILDER_GRADLE_VERSION, applyPluginWithProjectBuilderDir, 'runApp').run()
}
/**
* This test demonstrates a workaround for the problem in Gradle 3.0 or 3.1 by adding the functionality that has now
* moved to {@link org.gradle.initialization.LegacyTypesUtil} directly to the test.
*/
def "can use plugin built with 2.x to execute a test on top of ProjectBuilder run with Gradle 3.0 using added LegacyTypesUtil methods"() {
given:
def repoDir = publishHelloWorldPluginWithOldGradleVersion()
TestFile applyPluginWithProjectBuilderDir = temporaryFolder.createDir('apply-plugin-with-project-builder')
when:
applyPluginWithProjectBuilderDir.file('src/test/java/org/gradle/consumer/PluginTest.java') << """
package org.gradle.consumer;
import org.gradle.api.Project;
import org.gradle.api.Plugin;