JUnit test with Maven in a Jenkins plugin - java

I have a problem when I tried to run JUnit tests with Maven. For a Jenkins plug-in I wrote a class for test. For example: I have the class ConsoleParser in package com.jenkins_plugin in folder src/main/java. The JUnit test case is ConsoleParserTest in package com.jenkins_plugin in folder src/test. For running the JUnit test I added the dependency in the pom:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
</dependencies>
And I ran in cmd the next command: mvn -Dtest=ConsoleParserTest test
The problem is that I've got the following error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.
12:test (default-test) on project swatt_jenkins: No tests were executed! (Set -
DfailIfNoTests=false to ignore this error.) -> [Help 1]
The full pom.xml is:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<build>
<finalName>Jenkins_Plugin</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>emma-maven-plugin</artifactId>
<version>1.0-alpha-3</version>
<inherited>true</inherited>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>instrument</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.526</version>
</parent>
<groupId>Jenkins_Plugin</groupId>
<version>1.0</version>
<packaging>hpi</packaging>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
</dependencies>
</project>
Also, I must mention that with those settings I ran successfully the test but after adding findbugs it crashed. So, I removed findbugs and try to run the test again but the problem that I mentioned appeared. So, can someone explain what I have to do? I tried to add another version of JUnit, Surefire but I had the same problem and I don't understand why.

Several things:
add you JUnit classes to src/test/java not src/test
for your JUnit class use the scope "test"
E.g.:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
Also I recommend to manage your repositories in a repository manager such as Nexus, not in your POM:
http://books.sonatype.com/nexus-book/reference/maven-sect-single-group.html

Related

Eclipse returning "No tests found with test runner 'JUnit 5' when using Suites

I've been reading online for days and days but i'm still not sure i got the answer I need, or a way to fix this problem.
I have a set of Java tests that are using JUnit5 and Selenium.
This was my pom.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ces.cursos.timetracker</groupId>
<artifactId>primerosScripts3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>primerosScripts3</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.4.0</version>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.3.0</version>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
With it, I was able to run all tests successfully by selecting the package and going into "Run As > JUnit tests"
Now I want to create test suites to organize my tests.
I created a new package, and created a new class inside it with the following code:
package suites;
import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;
import com.tests.Testing.Test1;
import com.tests.Testing.Test2;
#Suite
#SelectClasses({Test1.class, Test2.class})
public class Suite1 {
}
My first problem was that the #Suite and #SelectClasses annotations were not recognized. I had to add the following dependency to my pom.xml file to be able to use them:
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite-api</artifactId>
<version>1.9.0</version>
<scope>test</scope>
</dependency>
Now, when I try to run this suite, I get the "No tests found with test runner JUnit 5" error.
I have a strong suspicion this has to do with my dependencies and JUnit versions, but after reading and reading online I'm not able to understand exactly what I need to do.
I'm a beginner so that might be why i'm having trouble understanding where to go next.

Using github repository as maven dependency

I have one project created which contains some reusable methods which can be used in other projects by adding it as a dependency. To do the same I have added the following in pom.xml file and when I run mvn clean deploy branch is created successfully with artifacts.
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.abc</groupId>
<artifactId>api-authenticator</artifactId>
<version>1.0.0</version>
<name>API Authenticator</name>
<description>Project to authenticate API usage</description>
<distributionManagement>
<repository>
<id>internal.repo</id>
<name>Staging Repository</name>
<url>file://${project.build.directory}/${version}</url>
</repository>
</distributionManagement>
<properties>
<github.global.server>github</github.global.server>
<java.version>11</java.version>
<java-jwt.version>3.16.0</java-jwt.version>
<jwks-rsa.version>0.18.0</jwks-rsa.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>${java-jwt.version}</version>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>jwks-rsa</artifactId>
<version>${jwks-rsa.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>com.github.github</groupId>
<artifactId>site-maven-plugin</artifactId>
<version>0.12</version>
<configuration>
<message>Maven artifacts for ${project.version}</message>
<noJekyll>true</noJekyll>
<outputDirectory>${project.build.directory}</outputDirectory>
<branch>refs/heads/${version}</branch>
<includes>
<include>**/*</include>
</includes>
<merge>true</merge>
<repositoryName>rwg-dip-api-authenticator</repositoryName>
<repositoryOwner>robert-walters</repositoryOwner>
<server>github</server>
</configuration>
<executions>
<execution>
<goals>
<goal>site</goal>
</goals>
<phase>deploy</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<altDeploymentRepository>
internal.repo::default::file://${project.build.directory}/${version}
</altDeploymentRepository>
</configuration>
</plugin>
</plugins>
</build>
</project>
In settings.xml (Maven home: /opt/homebrew/Cellar/maven/3.8.2/libexec) I have generated personal access token with all access required and added it.
<server>
<id>github</id>
<password>access_token</password>
</server>
To use this as a dependency I have added the following in the project where I want to reuse the functions and when I do reimport the dependency from IntelliJ I can see my internal project's dependency in external dependencies But when I run the project it shows java: package com.abc.util does not exist althoght I am getting the suggestions for the class in Intellj.
<repositories>
<repository>
<id>https://github.com/me/api-authenticator</id>
<url>https://github.com/me/api-authenticator/1.0.0</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<dependency>
<groupId>com.abc</groupId>
<artifactId>api-authenticator</artifactId>
<version>1.0.0</version>
</dependency>
I have gone through the below but it was not helpful for the above case
Hosting a Maven repository on github
https://www.baeldung.com/maven-repo-github
https://dev.to/iamthecarisma/hosting-a-maven-repository-on-github-site-maven-plugin-9ch
UPDATE
As M.Deinum has suggested I have removed spring-boot-maven-plugin and now I am able to use it as depency in other projects in Intellj and it works fine locally but when the pipeline execute to create build for the project mvn package steps fails with "The POM for com.abc:api-authenticator:jar:1.0.0 is missing, no dependency information available"
If you are ok with using an external service for that, you can check https://jitpack.io/ out.
It is able to build your maven project directly from a GitHub repository and then acts as a maven repository that is serving the artifact.
It takes time to download the artifact for the first time (as it builds the project only with the first request for the artifact), but then it reuses the already built artifacts for the next requests.

Error "TestEngine with ID 'junit-jupiter' failed to discover tests". Getting this error while trying to run JUnit tests in a maven project

I am trying to run tests in a project with Apache Maven 3.8.3, JDK 14, JUnit 5.8.1, jqwik 1.5.6
I'm using IntelliJ IDEA 2021.2.3 (Community Edition)
The libraries must be correctly imported but it still doesn't work.
When I try to run simple tests I 'm getting the following error message:
"Internal Error occurred.
org.junit.platform.commons.JUnitException: TestEngine with ID 'junit-jupiter' failed to discover tests"
Here is the pom.xml file. I'd appreciate any advice and thanks in advance!
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>tests</groupId>
<artifactId>tests</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>${project.basedir}/src</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/tests</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<includes>
<include>**/*Tests.java</include>
<include>**/*Examples.java</include>
<include>**/*Properties.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.8.1</version>
</dependency>
<dependency>
<groupId>net.jqwik</groupId>
<artifactId>jqwik</artifactId>
<version>1.5.6</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>14</maven.compiler.source>
<maven.compiler.target>14</maven.compiler.target>
</properties>
</project>

SonarQube doesn't analyze the main java code with IntelliJ and Maven

I'm using IntelliJ with Maven for my project and i have to analyze it with SonarQube, but when I scan my project with the command provided by the webApp it only analyzes the pom.xml file ignoring the rest of the project.
Analysis results
clean install sonar:sonar -Dsonar.host.url=http://localhost:9000 -Dsonar.login="the corresponding key here"
My pom.xml (what is inside the project tag):
<groupId>cl.itau.simulacionCredito</groupId>
<artifactId>SimulacionCreditoIntelliJ</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.beust/jcommander -->
<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
<version>1.72</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<excludes>
<exclude>**/HomeTest.java</exclude>
<exclude>**/PropuestaTest.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.0.0-M1</version>
</plugin>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.5.0.1254</version>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>SimulacionCredito</id>
<name>SimulacionCredito</name>
<url>file:C:\Users\Pc\IdeaProjects</url>
</repository>
</distributionManagement>
I also tried to use this inside the configuration tag:
<sonar.sources>src/main/java</sonar.sources>
And this happened:
Second analysis
My settings.xml in Maven's conf:
<pluginGroups>
<pluginGroup>org.sonarsource.scanner.maven</pluginGroup>
</pluginGroups>
<proxies>
</proxies>
<servers>
</servers>
<mirrors>
</mirrors>
<profiles>
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<sonar.host.url>
http://localhost:9000
</sonar.host.url>
</properties>
</profile>
</profiles>
I've been adding things to the POM because of different errors while trying to fix this.
I have the latest version of SonarQube installed.
Sonarqube works by analyzing jacoco outputs. I don't see any configs for jacoco in your pom. https://www.petrikainulainen.net/programming/maven/creating-code-coverage-reports-for-unit-and-integration-tests-with-the-jacoco-maven-plugin/ is a good tutorial on how to set it up.
You will also have to tell sonarqube where your jacoco.exec file is at.
https://docs.sonarqube.org/display/PLUG/Code+Coverage+by+Unit+Tests+for+Java+Project
So, the problem was that IntelliJ was configured with Java SE Development Kit 11, I downgraded to Java SE Development Kit 8u181 and configured the POM so Maven works with that change, I executed the scanner again and it worked.
Changes to pom.xml:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<sonar.sources>src/main/java</sonar.sources>
</properties>
added:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
New analysis results

java generics and annotations not supported in version 1.3 (travis integration)

I'm trying to integrate my github Java/PHP project with travis-ci environment. This is my travis configuration:
language: java
jdk:
- openjdk7
- oraclejdk7
script: mvn test
Below is the output that travis prints:
Using worker: bluebox-linux-1.worker.travis-ci.org:travis-linux-9
$ git clone --depth=50 --branch=master git://github.com/tkoomzaaskz/wealthy-laughing-duck.git tkoomzaaskz/wealthy-laughing-duck
Cloning into 'tkoomzaaskz/wealthy-laughing-duck'...
remote: Counting objects: 458, done.
remote: Compressing objects: 100% (263/263), done.
remote: Total 458 (delta 156), reused 390 (delta 96)
Receiving objects: 100% (458/458), 458.40 KiB, done.
Resolving deltas: 100% (156/156), done.
$ cd tkoomzaaskz/wealthy-laughing-duck
$ git checkout -qf 47d1ef528f19ad6d01288ac9a3d4c550a79b14f4
$ jdk_switcher use openjdk7
Switching to OpenJDK7 (java-1.7.0-openjdk-amd64), JAVA_HOME will be set to /usr/lib/jvm/java-7-openjdk-amd64
update-alternatives: error: no alternatives for apt.
update-alternatives: error: no alternatives for mozilla-javaplugin.so.
update-java-alternatives: plugin alternative does not exist: /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/IcedTeaPlugin.so
$ java -version
java version "1.7.0_15"
OpenJDK Runtime Environment (IcedTea7 2.3.7) (7u15-2.3.7-0ubuntu1~12.04.1)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)
$ javac -version
javac 1.7.0_15
$ mvn install --quiet -DskipTests=true
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project wealthy-laughing-duck: Compilation failure: Compilation failure:
[ERROR] /home/travis/build/tkoomzaaskz/wealthy-laughing-duck/src/main/java/com/blogspot/symfonyworld/wealthylaughingduck/dao/OutcomeDao.java:[19,8] error: generics are not supported in -source 1.3
[ERROR]
[ERROR] (use -source 5 or higher to enable generics)
[ERROR] /home/travis/build/tkoomzaaskz/wealthy-laughing-duck/src/main/java/com/blogspot/symfonyworld/wealthylaughingduck/model/Income.java:[12,1] error: annotations are not supported in -source 1.3
[ERROR]
[ERROR] (use -source 5 or higher to enable annotations)
[ERROR] /home/travis/build/tkoomzaaskz/wealthy-laughing-duck/src/main/java/com/blogspot/symfonyworld/wealthylaughingduck/model/User.java:[10,1] error: annotations are not supported in -source 1.3
The output says that I'm using the too old version of java to use annotations and generics. But these are nothing new and they have to be supported somehow (I guess). I've been looking at travis/java docs but found no option about java version (hence I tried to use different jdks). Can anyone point me what should I put into the travis config file?
edit:
following #hertzsprung, I ran mvn help:effective-pom and it returned following output (in fact, neither source nor target attribute are note defined for maven-compiler-plugin - what can I do about it?):
<!-- ====================================================================== -->
<!-- -->
<!-- Generated by Maven Help Plugin on 2013-03-24T08:15:13 -->
<!-- See: http://maven.apache.org/plugins/maven-help-plugin/ -->
<!-- -->
<!-- ====================================================================== -->
<!-- ====================================================================== -->
<!-- -->
<!-- Effective POM for project -->
<!-- 'com.blogspot.symfony-world:wealthy-laughing-duck:jar:1.0-SNAPSHOT' -->
<!-- -->
<!-- ====================================================================== -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.blogspot.symfony-world</groupId>
<artifactId>wealthy-laughing-duck</artifactId>
<version>1.0-SNAPSHOT</version>
<name>wealthy-laughing-duck</name>
<url>http://maven.apache.org</url>
<build>
<sourceDirectory>/var/www/github/wealthy-laughing-duck/src/main/java</sourceDirectory>
<scriptSourceDirectory>src/main/scripts</scriptSourceDirectory>
<testSourceDirectory>/var/www/github/wealthy-laughing-duck/src/test/java</testSourceDirectory>
<outputDirectory>/var/www/github/wealthy-laughing-duck/target/classes</outputDirectory>
<testOutputDirectory>/var/www/github/wealthy-laughing-duck/target/test-classes</testOutputDirectory>
<resources>
<resource>
<mergeId>resource-0</mergeId>
<directory>/var/www/github/wealthy-laughing-duck/src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<mergeId>resource-1</mergeId>
<directory>/var/www/github/wealthy-laughing-duck/src/test/resources</directory>
</testResource>
</testResources>
<directory>/var/www/github/wealthy-laughing-duck/target</directory>
<finalName>wealthy-laughing-duck-1.0-SNAPSHOT</finalName>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-4</version>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.3</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.3.2</version>
</plugin>
<plugin>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.3</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.6.1</version>
</plugin>
<plugin>
<artifactId>maven-plugin-plugin</artifactId>
<version>2.8</version>
</plugin>
<plugin>
<artifactId>maven-rar-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.0-beta-8</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.3</version>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>2.1</version>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.0.4</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.3</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1-beta-1</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-help-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Maven Repository Switchboard</name>
<url>http://repo1.maven.org/maven2</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Maven Plugin Repository</name>
<url>http://repo1.maven.org/maven2</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.thrift</groupId>
<artifactId>libthrift</artifactId>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.3</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.10.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.24</version>
</dependency>
</dependencies>
<reporting>
<outputDirectory>/var/www/github/wealthy-laughing-duck/target/site</outputDirectory>
</reporting>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 16 seconds
[INFO] Finished at: Sun Mar 24 20:15:13 CET 2013
[INFO] Final Memory: 11M/60M
[INFO] ------------------------------------------------------------------------
This is my source pom.xml content:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.blogspot.symfony-world</groupId>
<artifactId>wealthy-laughing-duck</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>wealthy-laughing-duck</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.thrift</groupId>
<artifactId>libthrift</artifactId>
<version>0.9.0</version>
</dependency>
<dependency>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
<type>jar</type>
<version>1.7.3</version>
</dependency>
<dependency>
<artifactId>hibernate-core</artifactId>
<groupId>org.hibernate</groupId>
<type>jar</type>
<version>4.1.10.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.24</version>
</dependency>
</dependencies>
</project>
Please try including the following code in your pom.xml for your Maven build config. I had the same problem as yourself and this seemed to do the trick for me:
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgument></compilerArgument>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Looks like for some weird reason travis is using source level and target jvm set to jdk 1.3. I think they should keep the maven default (which is 1.5), because this error caught me by surprise and it took some time to fix it, since I don't want to change my project configuration and behaviors according to external tools.
If you want to avoid modifying your pom.xml (which shouldn't be dependent from your continuous integration tool), you can configure travis to compile using approriate source level and target jvm:
language: java
jdk:
- oraclejdk7
- openjdk7
install: mvn install -Dmaven.compiler.target=1.5 -Dmaven.compiler.source=1.5 -DskipTests=true -B
script: mvn test -Dmaven.compiler.target=1.5 -Dmaven.compiler.source=1.5 -B
This will compile using 1.5 source level and produce bytecode targetted for a 1.5 jvm. You can specify 1.7 in place of 1.5 if you want to target 1.7.

Categories

Resources