You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Akom (Jira)" <ji...@apache.org> on 2020/04/17 16:00:00 UTC

[jira] [Commented] (SUREFIRE-1234) Allow to configure JVM for tests by referencing a toolchain entry

    [ https://issues.apache.org/jira/browse/SUREFIRE-1234?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17085891#comment-17085891 ] 

Akom commented on SUREFIRE-1234:
--------------------------------

Two comments on this.
 * I've tried to make a PR for this, and [the code changes are trivial|https://github.com/apache/maven-surefire/compare/master...akomakom:add-toolchains-support?expand=1], but:
 ** toolchains jar did not expose a way to access arbitrary toolchains until a later version than what surefire currently uses
 ** toolchains jar is baked into maven-core
 ** using a new version of toolchains dependency means upgrading maven core from 3.0 to 3.3.x (across the board)
 ** things break when I do this and it's a lot of work to fix.

 * I also own a plugin (*maven-forge-plugin*, not currently open sourced but used in [some projects|https://github.com/Terracotta-OSS/terracotta-parent/blob/581e257beb486bf70a2a9a049896f32e7a19d8c6/pom.xml#L87] that achieves the same effect (in recent version) in another way:
 ** it extends SurefirePlugin mojo and the two failsafe mojos and adds some code before super.execute().   This means that its configuration is a superset of failsafe/surefire.
 ** it depends on maven-core 3.3+
 ** it performs the toolchain lookup and sets the value of the *jvm* arg, fooling surefire
 ** it also sets JAVA_HOME env var in plugin configuration (and adds JAVA_HOME to excludedEnvironmentVariables)

Although this plugin is functionally adequate, its use requires that:
 * poms disable surefire/failsafe executions
 * poms change failsafe/surefire to my plugin
 * IDEs that are maven-aware no longer pick up test configuration from the pom unless you add a duplicate (inert) failsafe/surefire configuration blocks.

Since I use parent poms across most projects, the limitations are acceptable.

> Allow to configure JVM for tests by referencing a toolchain entry
> -----------------------------------------------------------------
>
>                 Key: SUREFIRE-1234
>                 URL: https://issues.apache.org/jira/browse/SUREFIRE-1234
>             Project: Maven Surefire
>          Issue Type: New Feature
>            Reporter: Gunnar Morling
>            Priority: Major
>             Fix For: Backlog
>
>
> There is the property "jvm" which allows to specify a specific JVM to run on the tests through Surefire. This puts in an absolute path into my POM, though, which makes the build less portable.
> Therefore I propose to allow an alternative option which allows to refer to specific JDKs configured through toolchains.xml:
> {code}
> <plugin>
>     <groupId>org.apache.maven.plugins</groupId>
>     <artifactId>maven-surefire-plugin</artifactId>
>     <configuration>
>         <toolchain>
>             <jdk>
>                 <version>1.7</version>
>                 <vendor>sun</vendor>
>             </jdk>
>         </toolchains> 
>     </configuration>
> </plugin>
> {code}
> Note that this allows to use a specific toolchain just for tests, independently what's configured as toolchain for the overall build through the maven-toolchain-plugin. This e.g. allows to run the build on JDK 8 but run tests on JDK/JRE 7 (which is a frequent requirement for our projects). Or one could have several Surefire executions, running tests on different Java versions.
> The toolchain to use should be injectable through a property, so one can easily configure it, e.g. for specific Jenkins runs: "... -Dsurefire.toolchain=jdk:1.7" or "... -Dsurefire.toolchain=jdk:1.7:sun".



--
This message was sent by Atlassian Jira
(v8.3.4#803005)