1

プロジェクトをビルドしてテストを実行するときに、正しいバージョンの alpn-boot を取り込むMaven POM を作成しようとしています。

ビルドを実行するときに(たとえば、環境変数を介してmvn -Dalpn-boot.version=8.1.8.v20160420 test、または環境変数として)「外部」からプロパティを注入している場合、全体が機能しますが、を使用してPOM内に補間しようとすると機能しません${java.version}

ファイル (スニペット)の次の設定でこれを達成するために、properties-maven-pluginを使用してみました。pom.xml

<project>
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>properties-maven-plugin</artifactId>
        <version>1.0.0</version>
        <executions>
          <execution>
            <phase>initialize</phase>
            <goals>
              <goal>read-project-properties</goal>
            </goals>
            <configuration>
              <files>
                <file>${project.basedir}/alpn-boot/jdk-${java.version}.properties</file>
              </files>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
      <groupId>org.mortbay.jetty.alpn</groupId>
      <artifactId>alpn-boot</artifactId>
      <version>${alpn-boot.version}</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

いずれかのプロパティ ファイルの内容:

$ cat alpn-boot/jdk-1.8.0_92.properties
alpn-boot.version=8.1.8.v20160420

基本的に同じ問題gmaven-plugin

<plugin>
  <groupId>org.codehaus.groovy.maven</groupId>
  <artifactId>gmaven-plugin</artifactId>
  <version>1.0</version>
  <executions>
    <execution>
      <phase>initialize</phase>
      <goals>
        <goal>execute</goal>
      </goals>
      <configuration>
        <source>
          alpnVersions = [ '1.8.0_92': '8.1.8.v20160420' ]
          project.properties['alpn-boot.version'] = alpnVersions[System.getProperty('java.version')]
        </source>
      </configuration>
    </execution>
  </executions>
</plugin>

どちらのアプローチでも、次のエラー メッセージが表示されます。

[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] 'dependencies.dependency.version' for org.mortbay.jetty.alpn:alpn-boot:jar must be a valid version but is '${alpn-boot.version}'. @ org.example:my-project:[unknown-version], /path/to/pom.xml, line 132, column 22
 @
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR]   The project org.example:my-project:1.0.0-rc3-SNAPSHOT (/path/to/pom.xml) has 1 error
[ERROR]     'dependencies.dependency.version' for org.mortbay.jetty.alpn:alpn-boot:jar must be a valid version but is '${alpn-boot.version}'. @ org.example:my-project:[unknown-version], /path/to/pom.xml, line 132, column 22
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
4

1 に答える 1

1

@khmarbaise のアドバイスに従い、サポートが必要な JDK の各バージョンにMaven プロファイルを追加しました。

<properties>
    <!-- Default alpn-boot version. See <profiles> for specific profiles. -->
    <alpn-boot.version>8.1.3.v20150130</alpn-boot.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.mortbay.jetty.alpn</groupId>
        <artifactId>alpn-boot</artifactId>
        <version>${alpn-boot.version}</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<!-- Profiles for selecting the correct version of alpn-boot for each JDK.
     see http://www.eclipse.org/jetty/documentation/current/alpn-chapter.html for reference. -->
<profiles>
    <profile>
        <id>jdk-1.8.0</id>
        <activation>
            <jdk>1.8.0</jdk>
        </activation>
        <properties>
            <alpn-boot.version>8.1.0.v20141016</alpn-boot.version>
        </properties>
    </profile>
    <!-- Lots of profiles [...] -->
    <profile>
        <id>jdk-1.8.0_92</id>
        <activation>
            <jdk>1.8.0_92</jdk>
        </activation>
        <properties>
            <alpn-boot.version>8.1.8.v20160420</alpn-boot.version>
        </properties>
    </profile>
</profiles>
于 2016-05-23T07:50:40.920 に答える