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

Propagation of Surefire/Failsafe plugin configuration does not correctly remove unresolvable properties #1916

Open
kwin opened this issue Jan 16, 2025 · 6 comments

Comments

@kwin
Copy link
Member

kwin commented Jan 16, 2025

Sometimes properties are not explicitly set in the pom.xml but are rather set through some other plugins. Most prominent example is https://www.jacoco.org/jacoco/trunk/doc/prepare-agent-mojo.html#propertyName.
As this property can obviously not be resolved when extracting the surefire/failsafe plugins, all unknown placeholder inside ${...} should just be replaced by the empty string.

For example I have this configuration in my pom.xml

<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<executions>
  <execution>
    <id>default-test</id>
    <phase>test</phase>
    <goals>
      <goal>test</goal>
    </goals>
    <configuration>
      <argLine>${test.opts.coverage} -Xmx512m</argLine>
    </configuration>
  </execution>
</executions>

Usually test.opts.coverage is populated from

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.12</version>
<executions>
  <execution>
    <id>pre-unit-test</id>
    <goals>
      <goal>prepare-agent</goal>
    </goals>
    <configuration>
      <propertyName>test.opts.coverage</propertyName>
    </configuration>
  </execution>
</executions>

This leads to the following error launching the auto-created JUnit configuration Reference to undefined variable test.opts.coverage because the VM arguments contain the unresolved ${test.opts.coverage} .
This is a regression of c8bcaaa.

@kwin
Copy link
Member Author

kwin commented Jan 16, 2025

I think

private TestLaunchArguments getTestLaunchArguments(MavenProject mavenProject, MojoExecution execution,
needs to be modified to both remove deferred and non-deferred unknown properties.

@kwin
Copy link
Member Author

kwin commented Jan 16, 2025

@treilhes Is that something you could look at?

@treilhes
Copy link
Contributor

Hello @kwin
I think your issue was already solved by #1827
Ensure you're using @{test.opts.coverage} instead of ${test.opts.coverage} as it is a deferred variable
and also appply the pluginManagement configuration provided in this post

I think it will solve your issue

@kwin
Copy link
Member Author

kwin commented Jan 18, 2025

M2E should not require POM changes. As this configuration works fine in CLI let's make it work in m2e...

@odrotbohm
Copy link

I am running into this problem on an m2e 2.7.0.20241126-1642 (within a recent STS). I've followed the advice given by the Mockito team here as recent Java versions require agents to be explicitly attached. With that configuration added to the project, all test executions in Eclipse now fail because m2e added an unexpanded -javaagent:${org.mockito:mockito-core:jar} as VM argument.

I essentially have to roll back the change recommended by the Mockito team because it affects all launch configurations of the project, and they only become executable once I manually remove that argument again.

The suggestion to use @{…} instead doesn't change a thing about the generated launch configurations unfortunately.

odrotbohm added a commit to spring-projects/spring-modulith that referenced this issue Jan 27, 2025
This reverts commit f6dd783. See [0] for details. Additionally, the change causes our integration builds to fail as the Mockito versions referred to by older Boot versions do not contain the necessary manifest entries.

[0] eclipse-m2e/m2e-core#1916 (comment)
odrotbohm added a commit to spring-projects/spring-modulith that referenced this issue Jan 27, 2025
This reverts commit 74f4417. See [0] for details. Additionally, the change causes our integration builds to fail as the Mockito versions referred to by older Boot versions do not contain the necessary manifest entries.

[0] eclipse-m2e/m2e-core#1916 (comment)
odrotbohm added a commit to spring-projects/spring-modulith that referenced this issue Jan 27, 2025
This reverts commit 003c428. See [0] for details. Additionally, the change causes our integration builds to fail as the Mockito versions referred to by older Boot versions do not contain the necessary manifest entries.

[0] eclipse-m2e/m2e-core#1916 (comment)
@treilhes
Copy link
Contributor

treilhes commented Feb 8, 2025

Hello @odrotbohm

By default m2e does not run any other plugin than surefire/failsafe to extract the unit test configuration as it may be too consuming.
If you plan to use properties generated by the execution of another plugin into surefire/failsafe configuration you need to provide this information explicitly to m2e.

To do that you need to configure the lifecycle mapping as follow:

...
    <build>
        <pluginManagement>
            <plugins>
                ....
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                ...
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>org.apache.maven.plugins</groupId>
                                        <artifactId>maven-dependency-plugin</artifactId>
                                        <versionRange>[1.0.0,)</versionRange>
                                        <goals>
                                            <goal>properties</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <execute>
                                            <runOnConfiguration>true</runOnConfiguration>
                                        </execute>
                                    </action>
                                </pluginExecution>
                                ....
                             </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
                ....
            </plugins>
        </pluginManagement>
    </build>
....

With this configuration you're telling m2e to run the maven-dependency-plugin during the configuration phase which include the unit test configuration generation.

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

3 participants