Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Travis Java build using different SDK for compilation and tests

Tags:

java

travis-ci

I have a library that uses Java 8 classes if they are available and for older JRE versions provides a fallback implementation. It means I have to compile using Java 8 (or higher) but I want to execute the tests with JDK 7 to test the fallback. I can not figure out how to do it in Travis.

like image 995
Lukas Avatar asked Apr 09 '26 11:04

Lukas


1 Answers

The easiest way is to create special Maven profile for Travis in pom.xml

   <profile>
      <id>travis</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
              <verbose>true</verbose>
              <fork>true</fork>
              <executable>/usr/lib/jvm/java-8-oracle/bin/javac</executable>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>   

And then activate it in .travis.yml

script: mvn install -P travis
like image 79
Lukas Avatar answered Apr 10 '26 23:04

Lukas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!