1

Maven 3.0.5 を使用しています。「maven-compile-plugin」に問題があります。基本的に、私は 2 つのプロジェクトを持っています。従来のプロジェクトは Java 6 にあり、新しいプロジェクトは Java 7 にあります。現在の JAVA_HOME は問題なく、次のとおりです。

$ echo $JAVA_HOME C:\Program Files (x86)\Java\jdk1.6.0_38

新しいプロジェクトでは、次の構成で maven-compile-plugin を使用します。

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
            <fork>true</fork>
            <verbose>true</verbose>
            <source>1.7</source>
            <target>1.7</target>
            <executable>${JDK7}</executable>
            <compilerVersion>1.7</compilerVersion>
        </configuration>
    </plugin>

settings.xml で JDK7 変数を宣言しました。

    <profiles>
    <profile>
        <id>compiler</id>
        <properties>
            <JDK6>C:\Program Files (x86)\Java\jdk1.6.0_38\bin\javac</JDK6>
            <JDK7>C:\Program Files (x86)\Java\jdk1.7.0_45\bin\javac</JDK7>
        </properties>
    </profile>
</profiles>
<activeProfiles>
    <activeProfile>compiler</activeProfile>
</activeProfiles>

新しいプロジェクトでは、enforcer プラグインを使用して、コンパイルされたソースが Java 7 に準拠していることも確認しているため、私の POM には次のものがあります。

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.3.1</version>
<executions>
    <execution>
        <id>enforce-versions</id>
        <phase>validate</phase>
        <goals>
            <goal>enforce</goal>
        </goals>
        <configuration>
            <rules>
                <requireJavaVersion>
                    <version>1.7</version>
                </requireJavaVersion>
            </rules>
        </configuration>
    </execution>
</executions>

Maven で理解できないのは、Java_HOME で定義されたコンパイラを常に使用することです。Java 6 にデフォルト設定されているため、新しいプロジェクトをビルドすると、Maven が Java 6 を使用するため、エンフォーサ プラグインは常に失敗します。

        $ mvn compile -X
    Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 14:51:28+0100)
    Maven home: c:\Dev\apache-maven-3.0.5
    Java version: 1.6.0_38, vendor: Sun Microsystems Inc.
    Java home: c:\Program Files (x86)\Java\jdk1.6.0_38\jre
    Default locale: fr_FR, platform encoding: Cp1252
    OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"
[...]
[INFO] --- maven-enforcer-plugin:1.3.1:enforce (enforce-versions) @ arom-wrapper ---
[WARNING] Rule 0: org.apache.maven.plugins.enforcer.RequireJavaVersion failed with message:
Detected JDK Version: 1.6.0-38 is not in the allowed range 1.7.

これについて私を助けてもらえますか?

4

1 に答える 1