Bluemix devops 构建管道是否支持 java 8 个应用程序?

Does Bluemix devops build pipeline support java 8 apps?

考虑到支持 java 8 的 Bluemix announcement。 我需要做什么才能在 IBM Bluesmix 构建管道(jazzhub 构建和部署)中编译我的 java 8 应用程序。

我已经设置了 java8 环境变量并使用以下命令重新启动应用程序:

cf set-env <myApp> JBP_CONFIG_IBMJDK "version: 1.8.+"
cf restage <myApp>

我正在使用的特定 'builder type' 是 'Maven',我收到的失败是在 java8 中的新日期和时间 类 附近。

[ERROR] <...>/services/TestHelperService.java:[3,17] package java.time does not exist
[ERROR] <...>/services/TestHelperService.java:[37,17] cannot find symbol
[ERROR] symbol:   class LocalDateTime
[ERROR] location: class <...>.services.TestHelperService

要使用 Java 8,您需要在构建 shell 命令中更改 JAVA_HOME 环境变量:

export JAVA_HOME=~/java8

例如:

#!/bin/bash
#export JAVA_HOME=~/java8 - Bluemix have changed the java8 location
export JAVA_HOME=/opt/IBM/java8
mvn -B package

嗨,这个解决方案对我不起作用,这是我的构建脚本

#!/bin/bash
echo "Java Home before $JAVA_HOME"
export JAVA_HOME=~/java8
echo "Java Home after $JAVA_HOME"
#mvn -B package -DskipTests
#mvn -B package

这里是控制台输出,您可以看到 JAVA_HOME 在 "export" 命令后没有被修改。

Checking out Revision 86514c6dc277b6903fcd6f51ca7c97ea733b1d42 (detached)
[ba6eba91-33a3-4b67-8efd-48962cf063ba] $ /bin/bash /tmp/hudson7007424628517212775.sh
Java Home before /home/jenkins/java
Java Home after /home/jenkins/java
Base artifact directory /home/jenkins/workspace/e92a4db8-6702-d006-0cdc-2a827a4e78a5/ba6eba91-33a3-4b67-8efd-48962cf063ba/target does not exist or is not a valid directory.
[xUnit] [INFO] - Starting to record.
[xUnit] [INFO] - Processing JUnit
[xUnit] [INFO] - [JUnit] - No test report file(s) were found with the pattern 'target/surefire-reports/TEST-*.xml' relative to '/home/jenkins/workspace/e92a4db8-6702-d006-0cdc-2a827a4e78a5/ba6eba91-33a3-4b67-8efd-48962cf063ba' for the testing framework 'JUnit'.  Did you enter a pattern relative to the correct directory?  Did you generate the result report(s) for 'JUnit'?
[xUnit] [ERROR] - No test reports found for the metric 'JUnit' with the resolved pattern 'target/surefire-reports/TEST-*.xml'. Configuration error?.
[xUnit] [INFO] - There are errors when processing test results.
[xUnit] [INFO] - Skipping tests recording.
Finished: SUCCESS

我可以确认在构建脚本中将 JAVA_HOME 设置为 /opt/IBM/java8 确实有效(在 2016-05-04 试用):

#!/bin/bash
 echo "Java home before: $JAVA_HOME"
 export JAVA_HOME=/opt/IBM/java8
 echo "Java home after: $JAVA_HOME"
 mvn -B package

这导致输出:

Java home before: /opt/IBM/java
Java home after: /opt/IBM/java8

如前所述,部署阶段必须将 JBP_CONFIG_IBMJDK 设置为 "version: 1.8.+"(cf set-env myApp JBP_CONFIG_IBMJDK "version: 1.8.+" 或环境中的行:manifest.yml 的部分)或(这就是我知道)你需要在 manifest.yml 中定义 buildpack: java_buildpack。自 2015 年 5 月起,java_buildpack 使用 JDK8。

当然,最后要注意的是更改 pom.xml 中 maven-compiler-plugin 的源版本——但这不是 Bluemix 特定的。

<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>(whatever version is current)</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
    </plugins>
    [...]
  </build>
  [...]
</project>

我还想在 Bluemix Jazz 构建管道中使用 Java8。仅更改 $JAVA_HOME 对我不起作用。我也必须更新 $PATH

export JAVA_HOME=/opt/IBM/java8
export PATH=$JAVA_HOME/bin:$PATH

在那之后,maven 在 java8 上 运行。