简体   繁体   English

Travis CI为什么认为我的代码是Java 1.3,以及如何解决它?

[英]Why does Travis CI think my code is Java 1.3, and how to fix it?

I'm trying out Travis CI with a Java project (pretty standard Maven, Spring setup). 我正在使用Java项目(相当标准的Maven,Spring安装程序)试用Travis CI。

Based on Travis docs, this should suffice in the .travis.yml file: 根据Travis文档,该文件在.travis.yml文件中就足够了:

language: java

Travis should notice the project's pom.xml and run mvn test by default. Travis应该注意项目的pom.xml并默认运行mvn test

However, the Travis build fails, giving me: 但是,Travis构建失败,给了我:

error: static import declarations are not supported in -source 1.3

My sources are Java 1.6. 我的资料来源是Java 1.6。 How and where should I tell that to Travis? 我该如何和在哪里告诉特拉维斯? The Java project docs don't mention -source option at all. Java项目文档根本没有提到-source选项。 (Also, 1.3 is a bit strange default, isn't it?) (同样,1.3是一个有点奇怪的默认值,不是吗?)

Got it working by customising install and script in .travis.yml like this: 通过自定义.travis.yml installscript来使其正常工作,如下所示:

language: java
install: mvn install -Dmaven.compiler.target=1.6 -Dmaven.compiler.source=1.6 -DskipTests=true
script: mvn test -Dmaven.compiler.target=1.6 -Dmaven.compiler.source=1.6

...as suggested in this answer . ...如该答案中建议

Anyway, I don't know where exactly the Java 1.3 default comes from, but IMHO that should be fixed. 无论如何,我不知道Java 1.3默认值的确切来源,但是恕我直言,应该对此进行修复。 Travis documentation talks of "reasonably good defaults" , but in this case that doesn't seem to be true. Travis 文档谈到“合理的默认值” ,但在这种情况下似乎并非如此。

Another option would be to add a lengthy piece of Maven XML to explicitly specify the source & target levels. 另一个选择添加一段冗长的Maven XML,以明确指定源和目标级别。 Well, personally I'm opposed to the idea of having to do that, just because a CI environment has silly defaults. 好吧,我个人反对这样做的想法,只是因为CI环境具有愚蠢的默认值。 (Isn't the whole point with Maven to avoid explicitly specifying stuff by using reasonable conventions?) With my current pom.xml everything works fine locally (eg mvn test ) as well as when deploying on Heroku. (使用Maven并不是要避免使用合理的约定来显式地指定内容吗?)使用我当前的pom.xml在本地以及在Heroku上部署时,一切都可以正常运行(例如mvn test )。

Update (2015, Java 8) 更新(2015,Java 8)

Just wanted to add that as of 2015, with a Java 8 codebase, you no longer need such customisations in Maven or Travis config. 只是想补充一点,从2015年开始,使用Java 8代码库,您不再需要在Maven或Travis配置中进行此类自定义。 You get away with the following: 您摆脱了以下情况:

In pom.xml , under top-level <project> : pom.xml顶级<project>

<properties>
    <java.version>1.8</java.version>
</properties>

And in .travis.yml : .travis.yml

language: java
jdk: oraclejdk8 

Which is nice. 很好 Note that JDK 8 must be specified, even when pom.xml sets Java version to 1.8. 请注意,即使pom.xml将Java版本设置为1.8,也必须指定JDK 8。 Travis otherwise defaults to JDK 7. Travis否则默认为JDK 7。

This is because you do not explicit set the source and target levels in your maven-compiler-plugin configuration in your pom.xml. 这是因为您没有在pom.xml的maven-compiler-plugin配置中显式设置源和目标级别。

Older versions of Maven then use the javac default which is Java 1.3 in OpenJDK (as opposed to 1.5 in Oracle Java). 然后,较早版本的Maven使用javac缺省值,即OpenJDK中的Java 1.3 (与Oracle Java中的1.5相对)。

This problem is certainly related to a Bug in Maven3 Ubuntu package , which is currently installed on Travis worker machines. 当然,此问题与Maven3 Ubuntu软件包中Bug有关,该软件包当前安装在Travis工作者计算机上。

Good News: In next Travis CI build environment, Maven 3.1.1 will be installed with Apache tarball release . 好消息:在下一个Travis CI构建环境中, 将在Apache tarball版本中安装Maven 3.1.1 This update is planned to be deployed in November 2013... 计划于2013年11月部署此更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM