You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "James Gough (JIRA)" <ji...@apache.org> on 2019/06/06 13:26:00 UTC

[jira] [Comment Edited] (MTOOLCHAINS-28) Toolchain does not respect fork

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

James Gough edited comment on MTOOLCHAINS-28 at 6/6/19 1:25 PM:
----------------------------------------------------------------

Hi [~madmax25],

In your configuration I think you need to move the location of the toolchain plugin, perhaps out to a profile e.g.

{code:xml}
<profiles>
        <profile>
            <id>toolchains</id>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-toolchains-plugin</artifactId>
                        <version>3.0.0-SNAPSHOT</version>
                        <executions>
                            <execution>
                                <goals><goal>toolchain</goal></goals>
                            </execution>
                        </executions>
                        <configuration>
                            <toolchains>
                                <jdk>
                                    <version>11</version>
                                </jdk>
                            </toolchains>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
{code}

You will then see in the logs:
{code:bash}
mvn -Ptoolchains --global-toolchains ./toolchains.xml clean install
{code}

{code:bash}
[INFO] --- maven-compiler-plugin:3.8.2-SNAPSHOT:testCompile (default-testCompile) @ my-toolchain-app ---
[INFO] Toolchain in maven-compiler-plugin: JDK[/Library/Java/JavaVirtualMachines/openjdk-12.jdk/Contents/Home/]
{code}

This is a little better, but there is still an error. This is because the compiler is looking for a groovy-eclipse-compiler toolchain. It appears the maven compiler plugin doesn't have the knowledge that it is supposed to use JDK, as it's the groovy-eclipse-compiler. I think this is reasonable. 

The code for this selection is here https://github.com/apache/maven-compiler-plugin/blob/master/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java#L580

At this point I'm not sure if that is intended and it would be better for you to provide a toolchain for the groovy-eclipse-compiler that has the install directory set as the path to javac. 

[~rfscholte] it would be good to get your opinion on this, I think the right path is for [~madmax25] to setup a tool chain for the groovy compiler, specifying the usage of javac as required. 


was (Author: jim__gough):
Hi [~madmax25],

In your configuration I think you need to move the location of the toolchain plugin, perhaps out to a profile e.g.

{code:xml}
<profiles>
        <profile>
            <id>toolchains</id>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-toolchains-plugin</artifactId>
                        <version>3.0.0-SNAPSHOT</version>
                        <executions>
                            <execution>
                                <goals><goal>toolchain</goal></goals>
                            </execution>
                        </executions>
                        <configuration>
                            <toolchains>
                                <jdk>
                                    <version>11</version>
                                </jdk>
                            </toolchains>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
{code}

You will then see in the logs:

{code:bash}
[INFO] --- maven-compiler-plugin:3.8.2-SNAPSHOT:testCompile (default-testCompile) @ my-toolchain-app ---
[INFO] Toolchain in maven-compiler-plugin: JDK[/Library/Java/JavaVirtualMachines/openjdk-12.jdk/Contents/Home/]
{code}

This is a little better, but there is still an error. This is because the compiler is looking for a groovy-eclipse-compiler toolchain. It appears this doesn't have the knowledge that it is supposed to use JDK.

The code for this selection is here https://github.com/apache/maven-compiler-plugin/blob/master/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java#L580

At this point I'm not sure if that is intended and it would be better for you to provide a toolchain for the groovy-eclipse-compiler that has the install directory set as the path to javac. 

[~rfscholte] it would be good to get your opinion on this, I think the right path is for [~madmax25] to setup a tool chain for the groovy compiler.

> Toolchain does not respect fork
> -------------------------------
>
>                 Key: MTOOLCHAINS-28
>                 URL: https://issues.apache.org/jira/browse/MTOOLCHAINS-28
>             Project: Maven Toolchains Plugin
>          Issue Type: Bug
>    Affects Versions: 1.1
>         Environment: Java 11, JDK 1.8, Maven 3.5.0
>            Reporter: Max Edmiston
>            Priority: Major
>
> I am using maven-compiler-plugin with fork option, configured for Java 11 using the toolchain plugin. I have set my local environment to use JDK 1.8 by default. Forked process will use JDK 1.8, not Java 11, even with toolchain. I have tried this with and without the jdkToolchain xml tag in maven-compiler-plugin configuration.
> Relevant pom.xml:
>  
> {code:xml}
> <plugin>
>     <groupId>org.apache.maven.plugins</groupId>
>     <artifactId>maven-compiler-plugin</artifactId>
>     <version>${maven-compiler-plugin.version}</version>
>     <configuration>
>         <compilerId>groovy-eclipse-compiler</compilerId>
>         <fork>true</fork>
>         <compilerArguments>
>             <javaAgentClass>lombok.launch.Agent</javaAgentClass>
>         </compilerArguments>
>     </configuration>
>     <dependencies>
>         <dependency>
>             <groupId>org.codehaus.groovy</groupId>
>             <artifactId>groovy-eclipse-compiler</artifactId>
>             <version>${groovy-eclipse-compiler.version}</version>
>         </dependency>
>         <dependency>
>             <groupId>org.codehaus.groovy</groupId>
>             <artifactId>groovy-eclipse-batch</artifactId>
>             <version>${groovy-eclipse-batch.version}</version>
>         </dependency>
>         <dependency>
>         <groupId>org.projectlombok</groupId>
>         <artifactId>lombok</artifactId>
>         <version>1.18.6</version>
>         </dependency>
>     </dependencies>
> </plugin>
> <plugin>
>     <groupId>org.apache.maven.plugins</groupId>
>     <artifactId>maven-toolchains-plugin</artifactId>
>     <version>1.1</version>
>     <executions>
>         <execution>
>             <goals>
>                 <goal>toolchain</goal>
>             </goals>
>         </execution>
>     </executions>
>     <configuration>
>         <toolchains>
>             <jdk>
>                 <version>11</version>
>                 <vendor>openjdk</vendor>
>             </jdk>
>         </toolchains>
>     </configuration>
> </plugin>
> {code}
>  
> toolchains.xml:
> {code:xml}
> <?xml version="1.0" encoding="UTF8"?> 
> <toolchains> 
>     <toolchain> 
>         <type>jdk</type> 
>         <provides> 
>             <version>11</version> 
>             <vendor>openjdk</vendor> 
>         </provides> 
>         <configuration> 
>             <jdkHome>/Library/Java/JavaVirtualMachines/openjdk-11.0.1.jdk/Contents/Home/</jdkHome> 
>         </configuration> 
>     </toolchain> 
> </toolchains>
> {code}
> Sample error:
> {code:java}
> [INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile)  ---
> [INFO] Toolchain in maven-compiler-plugin: JDK[/Library/Java/JavaVirtualMachines/openjdk-11.0.1.jdk/Contents/Home/]
> [INFO] Changes detected - recompiling the module!
> [INFO] Using Groovy-Eclipse compiler to compile both Java and Groovy files
> [INFO] Compiling in a forked process using /Users/max.edmiston/.m2/repository/org/codehaus/groovy/groovy-eclipse-batch/2.5.4-01/groovy-eclipse-batch-2.5.4-01.jar
> [INFO] -------------------------------------------------------------
> [ERROR] COMPILATION ERROR : 
> [INFO] -------------------------------------------------------------
> [ERROR] Failure executing groovy-eclipse compiler:
> ----------
> 1. ERROR in ***Test.java (at line 39)
> 	***.stream().findFirst().orElseThrow();
> 	                          ^^^^^^^^^^^
> The method orElseThrow(Supplier<? extends X>) in the type Optional<Thing> is not applicable for the arguments ()
> ...
> ----------
> 5 problems (5 errors)
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)