简体   繁体   中英

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).

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

language: java

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

However, the Travis build fails, giving me:

error: static import declarations are not supported in -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?)

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

...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. Travis documentation talks of "reasonably good defaults" , but in this case that doesn't seem to be true.

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 (eg mvn test ) as well as when deploying on Heroku.

Update (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. You get away with the following:

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

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

And in .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. Travis otherwise defaults to 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.

Older versions of Maven then use the javac default which is Java 1.3 in OpenJDK (as opposed to 1.5 in Oracle Java).

This problem is certainly related to a Bug in Maven3 Ubuntu package , which is currently installed on Travis worker machines.

Good News: In next Travis CI build environment, Maven 3.1.1 will be installed with Apache tarball release . This update is planned to be deployed in November 2013...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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