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

Test framework configuration fails with Gradle 7.3 #296

Closed
melix opened this issue Nov 2, 2021 · 5 comments
Closed

Test framework configuration fails with Gradle 7.3 #296

melix opened this issue Nov 2, 2021 · 5 comments
Assignees

Comments

@melix
Copy link
Collaborator

melix commented Nov 2, 2021

Expected Behavior

A project generated from Launch should work out of the box using Gradle 7.3.

Actual Behaviour

Running the build fails with:

A problem occurred configuring root project 'demo'.

The value for task ':test' property 'testFrameworkProperty' is final and cannot be changed any further.

The stack trace leads to another ordering issue in the Gradle plugin:

        at io.micronaut.gradle.MicronautLibraryPlugin.lambda$apply$4(MicronautLibraryPlugin.java:101)
        at org.gradle.configuration.internal.DefaultUserCodeApplicationContext$CurrentApplication$1.execute(DefaultUserCodeApplicationContext.java:123)
        at org.gradle.configuration.internal.DefaultListenerBuildOperationDecorator$BuildOperationEmittingAction$1.run(DefaultListenerBuildOperationDecorator.java:152)

Steps To Reproduce

Create a Gradle project using Micronaut Launch, don't specify any testing framework.
Run the build with Gradle 7.3-rc-3, see it fail.

Workaround is to add:

tasks.withType(Test).configureEach {
	useJUnitPlatform()
}

to the build file.

Environment Information

No response

Example Application

No response

Version

3.1.3

@hantsy
Copy link

hantsy commented Nov 10, 2021

Got the same error when upgrading to Gradle 7.3.

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'demo'.
> The value for task ':test' property 'testFrameworkProperty' is final and cannot be changed any further.

@wetted
Copy link
Member

wetted commented Nov 10, 2021

Also seeing the same problem. We're using Micronaut 2.5.12 and the plugin 1.5.4 on AdoptOpenJDK 8, and get the same failure trying to upgrade to Gradle 7.3. I also get the same problem creating Micronaut 2 or 3 apps in Launch and upgrading them to Gradle 7.3.

On our projects we're using the Gradle 7 version catalog feature across all our projects, so it's in our best interest to track these Gradle upgrades, but this issue is a blocker for that. I will try the workaround noted above.

This is the error I get upgrading a default Launch project (3.1.3, JDK8, JUnit5):

% ./gradlew wrapper --gradle-version=7.3
FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'gradle73FailWithMn3'.
> The value for task ':test' property 'testFrameworkProperty' is final and cannot be changed any further.

@codepitbull
Copy link

We ran into the same issue.
Looks like gradle did something I NEVER expected to happen for a patch release: They changed behavior:

https://githubmemory.com/repo/gradle/gradle/issues/18606

msgilligan added a commit to ConsensusJ/btcproxy that referenced this issue Nov 18, 2021
hjwilli added a commit to carnival-data/carnival-demo-biomedical that referenced this issue Nov 19, 2021
Error seems to have been introduced with micronaut and gradle 7.3.0.  Using gradle v7.2.0 instead of latest in Dockerfile.

See micronaut-projects/micronaut-gradle-plugin#296

Ref #9
@tresat
Copy link

tresat commented Nov 22, 2021

This is going to be changed on the Gradle side. See: gradle/gradle#19058

@melix
Copy link
Collaborator Author

melix commented Dec 1, 2021

I understand that Gradle is going to revert the change, but I'm not sure how we can prepare for the change in 8.0. Basically, we have this code:

if (testRuntime != MicronautTestRuntime.NONE) {
// set JUnit 5 platform
project.getTasks().withType(Test.class, test -> {
if (!test.getTestFramework().getClass().getName().contains("JUnitPlatform")) {
test.useJUnitPlatform();
}
});
}

which is executed in an afterEvaluate. The idea is to say "if the user didn't configure a specific test framework, use JUnit Platform". It has to be executed in an afterEvaluate because we don't know when the user is "done" with configuration. I also understand that this is basically broken because if the user configures test options, then they would be ignored when this is called.

An option would be to configure useJUnitPlatform(), but if the test framework is set, change it.

@melix melix closed this as completed Feb 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants