Travis CI为什么认为我的代码是Java 1.3,以及如何解决它? [英] Why does Travis CI think my code is Java 1.3, and how to fix it?

查看:104
本文介绍了Travis CI为什么认为我的代码是Java 1.3,以及如何解决它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Java项目(相当标准的Maven,Spring安装程序)试用Travis CI.

I'm trying out Travis CI with a Java project (pretty standard Maven, Spring setup).

基于Travis文档,这在.travis.yml文件中就足够了:

Based on Travis docs, this should suffice in the .travis.yml file:

language: java

Travis应该注意到项目的pom.xml并默认运行mvn test.

Travis should notice the project's pom.xml and run mvn test by default.

但是,Travis构建失败,给了我

However, the Travis build fails, giving me:

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

我的资料来源是Java 1.6.我该如何和在哪里告诉特拉维斯? Java项目文档根本没有提到-source选项. (而且1.3的默认设置有点奇怪,不是吗?)

My sources are Java 1.6. How and where should I tell that to Travis? The Java project docs don't mention -source option at all. (Also, 1.3 is a bit strange default, isn't it?)

推荐答案

通过在.travis.yml中自定义installscript来使其正常工作,如下所示:

Got it working by customising install and script in .travis.yml like this:

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

...如建议回答.

无论如何,我不知道Java 1.3默认值的确切来源,但是恕我直言,应该对此进行修复. Travis 有关合理的默认值"的文档讨论,但是在此情况似乎并非如此.

Anyway, I don't know where exactly the Java 1.3 default comes from, but IMHO that should be fixed. Travis documentation talks of "reasonably good defaults", but in this case that doesn't seem to be true.

另一种选择添加冗长的Maven XML 以明确指定来源和目标水平.嗯,就我个人而言,我反对这样做的想法,因为CI环境具有愚蠢的默认设置. (使用Maven并不是要避免通过使用 reasonable 约定明确地指定内容吗?)在我当前的pom.xml范围内,一切正常(例如,在mvn test上)以及在Heroku上部署时,一切正常

Another option would be to add a lengthy piece of Maven XML to explicitly specify the source & target levels. Well, personally I'm opposed to the idea of having to do that, just because a CI environment has silly defaults. (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 (e.g. mvn test) as well as when deploying on Heroku.

只需添加到2015年,使用 Java 8 代码库,您就不再需要在Maven或Travis配置中进行此类自定义.您可以摆脱以下条件:

Just wanted to add that as of 2015, with a Java 8 codebase, you no longer need such customisations in Maven or Travis config. You get away with the following:

pom.xml中,在顶级<project>下:

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

.travis.yml中:

language: java
jdk: oraclejdk8 

哪个好.请注意,即使pom.xml将Java版本设置为1.8,也必须指定JDK 8 . Travis否则默认为JDK 7.

Which is nice. Note that JDK 8 must be specified, even when pom.xml sets Java version to 1.8. Travis otherwise defaults to JDK 7.

这篇关于Travis CI为什么认为我的代码是Java 1.3,以及如何解决它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆