I am new in the world of travis CI and would like to make my first build with it, only that when I go to configure it via the .travis.yml file it raises me the following error
[INFO] /home/travis/build/vincenzopalazzo/ilveroprogrammatorebotjava/app/src/main/java/top/gigabox/ilveroprogrammatore/persistenza/DAOGenericoJson.java: Recompile with -Xlint:unchecked for details.
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/travis/build/vincenzopalazzo/ilveroprogrammatorebotjava/app/src/main/java/top/gigabox/ilveroprogrammatore/Bot.java:[100,53] package it.unibas.utilita does not exist
[ERROR] /home/travis/build/vincenzopalazzo/ilveroprogrammatorebotjava/app/src/main/java/top/gigabox/ilveroprogrammatore/Bot.java:[122,39] package it.unibas.utilita does not exist
[ERROR] /home/travis/build/vincenzopalazzo/ilveroprogrammatorebotjava/app/src/main/java/top/gigabox/ilveroprogrammatore/Bot.java:[125,39] package it.unibas.utilita does not exist
[INFO] 3 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.953 s
[INFO] Finished at: 2018-08-14T11:06:22Z
[INFO] Final Memory: 24M/180M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile) on project app: Compilation failure: Compilation failure:
[ERROR] /home/travis/build/vincenzopalazzo/ilveroprogrammatorebotjava/app/src/main/java/top/gigabox/ilveroprogrammatore/Bot.java:[100,53] package it.unibas.utilita does not exist
[ERROR] /home/travis/build/vincenzopalazzo/ilveroprogrammatorebotjava/app/src/main/java/top/gigabox/ilveroprogrammatore/Bot.java:[122,39] package it.unibas.utilita does not exist
[ERROR] /home/travis/build/vincenzopalazzo/ilveroprogrammatorebotjava/app/src/main/java/top/gigabox/ilveroprogrammatore/Bot.java:[125,39] package it.unibas.utilita does not exist
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
The command "eval mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V " failed. Retrying, 2 of 3.
Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T07:58:13Z)
Maven home: /usr/local/maven-3.5.2
Java version: 1.8.0_151, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-oracle/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.4.0-101-generic", arch: "amd64", family: "unix"
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building app 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # app ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/travis/build/vincenzopalazzo/ilveroprogrammatorebotjava/app/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) # app ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 7 source files to /home/travis/build/vincenzopalazzo/ilveroprogrammatorebotjava/app/target/classes
[INFO] /home/travis/build/vincenzopalazzo/ilveroprogrammatorebotjava/app/src/main/java/top/gigabox/ilveroprogrammatore/persistenza/DAOGenericoJson.java: /home/travis/build/vincenzopalazzo/ilveroprogrammatorebotjava/app/src/main/java/top/gigabox/ilveroprogrammatore/persistenza/DAOGenericoJson.java uses unchecked or unsafe operations.
[INFO] /home/travis/build/vincenzopalazzo/ilveroprogrammatorebotjava/app/src/main/java/top/gigabox/ilveroprogrammatore/persistenza/DAOGenericoJson.java: Recompile with -Xlint:unchecked for details.
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/travis/build/vincenzopalazzo/ilveroprogrammatorebotjava/app/src/main/java/top/gigabox/ilveroprogrammatore/Bot.java:[100,53] package it.unibas.utilita does not exist
[ERROR] /home/travis/build/vincenzopalazzo/ilveroprogrammatorebotjava/app/src/main/java/top/gigabox/ilveroprogrammatore/Bot.java:[122,39] package it.unibas.utilita does not exist
[ERROR] /home/travis/build/vincenzopalazzo/ilveroprogrammatorebotjava/app/src/main/java/top/gigabox/ilveroprogrammatore/Bot.java:[125,39] package it.unibas.utilita does not exist
[INFO] 3 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.937 s
[INFO] Finished at: 2018-08-14T11:06:27Z
[INFO] Final Memory: 19M/195M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile) on project app: Compilation failure: Compilation failure:
[ERROR] /home/travis/build/vincenzopalazzo/ilveroprogrammatorebotjava/app/src/main/java/top/gigabox/ilveroprogrammatore/Bot.java:[100,53] package it.unibas.utilita does not exist
[ERROR] /home/travis/build/vincenzopalazzo/ilveroprogrammatorebotjava/app/src/main/java/top/gigabox/ilveroprogrammatore/Bot.java:[122,39] package it.unibas.utilita does not exist
[ERROR] /home/travis/build/vincenzopalazzo/ilveroprogrammatorebotjava/app/src/main/java/top/gigabox/ilveroprogrammatore/Bot.java:[125,39] package it.unibas.utilita does not exist
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
The command "eval mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V " failed. Retrying, 3 of 3.
Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T07:58:13Z)
Maven home: /usr/local/maven-3.5.2
Java version: 1.8.0_151, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-oracle/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.4.0-101-generic", arch: "amd64", family: "unix"
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building app 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # app ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/travis/build/vincenzopalazzo/ilveroprogrammatorebotjava/app/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) # app ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 7 source files to /home/travis/build/vincenzopalazzo/ilveroprogrammatorebotjava/app/target/classes
[INFO] /home/travis/build/vincenzopalazzo/ilveroprogrammatorebotjava/app/src/main/java/top/gigabox/ilveroprogrammatore/persistenza/DAOGenericoJson.java: /home/travis/build/vincenzopalazzo/ilveroprogrammatorebotjava/app/src/main/java/top/gigabox/ilveroprogrammatore/persistenza/DAOGenericoJson.java uses unchecked or unsafe operations.
[INFO] /home/travis/build/vincenzopalazzo/ilveroprogrammatorebotjava/app/src/main/java/top/gigabox/ilveroprogrammatore/persistenza/DAOGenericoJson.java: Recompile with -Xlint:unchecked for details.
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/travis/build/vincenzopalazzo/ilveroprogrammatorebotjava/app/src/main/java/top/gigabox/ilveroprogrammatore/Bot.java:[100,53] package it.unibas.utilita does not exist
[ERROR] /home/travis/build/vincenzopalazzo/ilveroprogrammatorebotjava/app/src/main/java/top/gigabox/ilveroprogrammatore/Bot.java:[122,39] package it.unibas.utilita does not exist
[ERROR] /home/travis/build/vincenzopalazzo/ilveroprogrammatorebotjava/app/src/main/java/top/gigabox/ilveroprogrammatore/Bot.java:[125,39] package it.unibas.utilita does not exist
[INFO] 3 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.895 s
[INFO] Finished at: 2018-08-14T11:06:33Z
[INFO] Final Memory: 18M/198M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile) on project app: Compilation failure: Compilation failure:
[ERROR] /home/travis/build/vincenzopalazzo/ilveroprogrammatorebotjava/app/src/main/java/top/gigabox/ilveroprogrammatore/Bot.java:[100,53] package it.unibas.utilita does not exist
[ERROR] /home/travis/build/vincenzopalazzo/ilveroprogrammatorebotjava/app/src/main/java/top/gigabox/ilveroprogrammatore/Bot.java:[122,39] package it.unibas.utilita does not exist
[ERROR] /home/travis/build/vincenzopalazzo/ilveroprogrammatorebotjava/app/src/main/java/top/gigabox/ilveroprogrammatore/Bot.java:[125,39] package it.unibas.utilita does not exist
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
The command "eval mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V " failed 3 times.
The command "mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V" failed and exited with 1 during .
Your build has been stopped.
my .travis.yml file is the following:
language: java
jdk:
- oraclejdk7
- oraclejdk8
- oraclejdk9
before_install:
- cd app
script: mvn clean verify
sudo: disable
my construction tool is maven whose verson is the following:
Apache Maven 3.3.9
Maven home: /usr/share/maven
Java version: 1.8.0_171, vendor: Oracle Corporation
Java home: /usr/local/java/jdk1.8.0_171/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.10.0-38-generic", arch: "amd64", family: "unix"
my pom.xml file is the following:
<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>
<groupId>top.gigabox</groupId>
<artifactId>app</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>app</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.25</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>top.gigabox.ilveroprogrammatore.Bot</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
the project on which I want to work travis is the following:project
There is a missing dependency in your pom that contains the it.unibas.utilita.Console class.
This one probably as your previous question suggest:
<dependency>
<groupId>unibas</groupId>
<artifactId>utilita</artifactId>
<version>0.1</version>
<scope>system</scope>
<systemPath>/home/vincenzo/MEGA/Programmazione/myLib/java/utilita.jar</systemPath>
</dependency>
Related
I've spent hours trying to release a project to github with Maven. This is usually not a problem but for some reason it is for this project and I don't understand why. I'm using Maven 3.8.5 with Java 1.8.0_312 and git 2.36.1. Here's the 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>se.company.myproject</groupId>
<artifactId>myproject</artifactId>
<version>4.0.0</version>
<packaging>pom</packaging>
<name>myproject-base</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<slf4j.version>1.7.36</slf4j.version>
</properties>
<modules>
<module>module1</module>
<module>module2</module>
<module>module3</module>
</modules>
<scm>
<connection>scm:git:ssh://git#github.com/mycompany/myproject.git</connection>
<developerConnection>scm:git:ssh://git#github.com/mycompany/myproject.git</developerConnection>
<url>https://github.com/mycompany/myproject.git</url>
<tag>4.0.0</tag>
</scm>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>se.company.myproject</groupId>
<artifactId>some-internal-dependency</artifactId>
<version>5.0.1</version>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.9.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<tagNameFormat>#{project.version}</tagNameFormat>
<autoVersionSubmodules>true</autoVersionSubmodules>
</configuration>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>company-releases</id>
<name>Internal Releases</name>
<url>https://company.se/company-maven-releases/</url>
</repository>
<snapshotRepository>
<id>company-snapshots</id>
<name>Internal Snapshots</name>
<url>https://company.se/company-maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
<repositories>
<repository>
<id>company-releases</id>
<url>https://company.se/company-maven-releases/</url>
</repository>
</repositories>
</project>
When I run maven release:prepare I get this:
[INFO] [INFO] --- maven-jar-plugin:2.4:jar (default-jar) # myproject-module3 ---
[INFO] [INFO] Building jar: /Users/me/code/module3/target/myproject-module3-4.0.0.jar
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] Reactor Summary for myproject-base 4.0.0:
[INFO] [INFO]
[INFO] [INFO] myproject-base ..................................... SUCCESS [ 0.059 s]
[INFO] [INFO] module1............................................. SUCCESS [ 1.097 s]
[INFO] [INFO] module2 ............................................ SUCCESS [ 0.603 s]
[INFO] [INFO] module3 ............................................ SUCCESS [ 0.046 s]
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] BUILD SUCCESS
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] Total time: 1.878 s
[INFO] [INFO] Finished at: 2022-05-20T14:29:16+02:00
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [prepare] 11/17 scm-commit-release
[INFO] Checking in modified POMs...
[INFO] Executing: /bin/sh -c cd '/Users/me/code/myproject' && 'git' 'add' '--' 'pom.xml' 'module1/pom.xml' 'module2/pom.xml' 'module3/pom.xml'
[INFO] Working directory: /Users/me/code/myproject
[INFO] Executing: /bin/sh -c cd '/Users/me/code/myproject' && 'git' 'rev-parse' '--show-prefix'
[INFO] Working directory: /Users/me/code/myproject
[INFO] Executing: /bin/sh -c cd '/Users/me/code/myproject' && 'git' 'status' '--porcelain' '.'
[INFO] Working directory: /Users/me/code/myproject
[WARNING] Ignoring unrecognized line: ?? module1/pom.xml.releaseBackup
[WARNING] Ignoring unrecognized line: ?? module2/pom.xml.releaseBackup
[WARNING] Ignoring unrecognized line: ?? pom.xml.releaseBackup
[WARNING] Ignoring unrecognized line: ?? release.properties
[WARNING] Ignoring unrecognized line: ?? module3/pom.xml.releaseBackup
[INFO] Executing: /bin/sh -c cd '/Users/me/code/myproject' && 'git' 'commit' '--verbose' '-F' '/var/folders/xb/pl4xth9n5qbgksbyy2fy5lm80000gn/T/maven-scm-1737591658.commit'
[INFO] Working directory: /Users/me/code/myproject
[INFO] Executing: /bin/sh -c cd '/Users/me/code/myproject' && 'git' 'symbolic-ref' 'HEAD'
[INFO] Working directory: /Users/me/code/myproject
[INFO] Executing: /bin/sh -c cd '/Users/me/code/myproject' && 'git' 'push' 'ssh:********#github.com/company/myproject.git' 'refs/heads/main:refs/heads/main'
[INFO] Working directory: /Users/me/code/myproject
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for myproject-base 3.0.1-SNAPSHOT:
[INFO]
[INFO] myproject-base ........................................ FAILURE [ 8.100 s]
[INFO] module1 ............................................... SKIPPED
[INFO] module2 ............................................... SKIPPED
[INFO] module3 ............................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.207 s
[INFO] Finished at: 2022-05-20T14:29:18+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:3.0.0-M5:prepare (default-cli) on project myproject: Unable to commit files
[ERROR] Provider message:
[ERROR] The git-push command failed.
[ERROR] Command output:
[ERROR] To ssh://github.com/company/myproject.git
[ERROR] ! [rejected] main -> main (non-fast-forward)
[ERROR] error: failed to push some refs to 'ssh://github.com/company/myproject.git'
[ERROR] hint: Updates were rejected because the tip of your current branch is behind
[ERROR] hint: its remote counterpart. Integrate the remote changes (e.g.
[ERROR] hint: 'git pull ...') before pushing again.
[ERROR] hint: See the 'Note about fast-forwards' in 'git push --help' for details.
[ERROR]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
I can push (and pull) just fine from the command line by using the git command. I've tried different versions of the maven-release-plugin to no avail. I've even deleted the entire GitHub repository and pushed it again from my local machine but still, I get the same error. What could be causing this?
A mvn -X prepare should show you which commit is checked out from your git:ssh://git#github.com/mycompany/myproject.git
Compare it with the latest commit on GitHub to understand the difference.
Trying to use an exec goal to do a git pull before mvn release is possible, but it is better to identify first why there is a remote commit that you do not have locally.
when I do a maven clean install, the compilation fails and maven reports a compilation error occurred. It does not however show the class where this happened when using groovy-eclipse-compiler. The plugin config is as below:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<!-- 2.8.0-01 and later require maven-compiler-plugin 3.0 or higher -->
<version>3.1</version>
<configuration>
<!-- Using the groovy-eclipse-compiler plugin because the gmaven plugin doesn't support compilation -->
<compilerId>groovy-eclipse-compiler</compilerId>
<!-- set verbose to be true if you want lots of uninteresting messages -->
<verbose>true</verbose>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
<encoding>ISO-8859-1</encoding>
</configuration>
<dependencies>
<dependency>
<artifactId>maven-compiler-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.8.0-01</version>
</dependency>
<!-- for 2.8.0-01 and later you must have an explicit dependency on
groovy-eclipse-batch -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<!-- <version>1.8.6-01</version> -->
<!-- or choose a different compiler version -->
<version>2.1.5-03</version>
<!-- <version>1.7.10-06</version> -->
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>${groovy.version}</version>
</dependency>
</dependencies>
</plugin>
And the output from maven is as below:
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # myproject ---
[INFO] Changes detected - recompiling the module!
[INFO] Using Groovy-Eclipse compiler to compile both Java and Groovy files
[INFO] Classpath:
[INFO] All args: []
[INFO] 17 files left.
[INFO] 16 files left.
[INFO] 15 files left.
[INFO] 14 files left.
[INFO] 13 files left.
[INFO] 12 files left.
[INFO] 11 files left.
[INFO] 10 files left.
[INFO] 9 files left.
[INFO] 8 files left.
[INFO] 7 files left.
[INFO] 6 files left.
[INFO] 5 files left.
[INFO] 4 files left.
[INFO] 3 files left.
[INFO] 2 files left.
[INFO] 1 file left.
[INFO] 0 files left.
[INFO] Compilation complete. Compiled 18 files.
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] Found 1 error and 0 warnings.
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.337 s
[INFO] Finished at: 2015-08-20T17:43:11-07:00
[INFO] Final Memory: 21M/221M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project myproject: Compilation failure
[ERROR] Found 1 error and 0 warnings.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
Adding <showWarnings>true</showWarnings> did show up the class with the compiler error along with a bunch of other compiler warnings such as unchecked conversion etc., however an error should have shown up without having to put this.
I've created a bare-bone Maven project, completely empty except the pom.xml.
With this pom (note that parent element is commented-out):
<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>springboot-test</groupId>
<artifactId>springboot-test</artifactId>
<version>1.0.0-SNAPSHOT</version>
<!-- <parent> -->
<!-- <groupId>org.springframework.boot</groupId> -->
<!-- <artifactId>spring-boot-starter-parent</artifactId> -->
<!-- <version>1.1.9.RELEASE</version> -->
<!-- </parent> -->
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Sample run:
$ mvn exec:java -Dexec.mainClass=test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building springboot-test 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- exec-maven-plugin:1.3.2:java (default-cli) # springboot-test ---
[WARNING] Warning: killAfter is now deprecated. Do you need it ? Please comment on MEXEC-6.
[WARNING]
java.lang.ClassNotFoundException: test
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:281)
at java.lang.Thread.run(Thread.java:745)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.480 s
[INFO] Finished at: 2014-12-05T13:45:34-05:00
[INFO] Final Memory: 8M/176M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.3.2:java (default-cli) on project springboot-test: An exception occured while executing the Java class. test -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
This is expected (there's no clas test in this project).
Using this pom (i.e. just un-commenting parent):
<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>springboot-test</groupId>
<artifactId>springboot-test</artifactId>
<version>1.0.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.9.RELEASE</version>
</parent>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Sample run:
$ mvn exec:java -Dexec.mainClass=test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building springboot-test 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> exec-maven-plugin:1.2.1:java (default-cli) > validate # springboot-test >>>
[INFO]
[INFO] <<< exec-maven-plugin:1.2.1:java (default-cli) < validate # springboot-test <<<
[INFO]
[INFO] --- exec-maven-plugin:1.2.1:java (default-cli) # springboot-test ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.550 s
[INFO] Finished at: 2014-12-05T13:45:27-05:00
[INFO] Final Memory: 12M/178M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project springboot-test: The parameters 'mainClass' for goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java are missing or invalid -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginParameterException
Same thing happens with exec-maven-plugin:1.3.2:
$ mvn org.codehaus.mojo:exec-maven-plugin:1.3.2:java -Dexec.mainClass=test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building springboot-test 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- exec-maven-plugin:1.3.2:java (default-cli) # springboot-test ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.400 s
[INFO] Finished at: 2014-12-05T13:52:46-05:00
[INFO] Final Memory: 6M/157M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.3.2:java (default-cli) on project springboot-test: The parameters 'mainClass' for goal org.codehaus.mojo:exec-maven-plugin:1.3.2:java are missing or invalid -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginParameterException
Additional information:
$ java -version
java version "1.8.0_11"
Java(TM) SE Runtime Environment (build 1.8.0_11-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)
$ mvn -v
Apache Maven 3.2.2 (45f7c06d68e745d05611f7fd14efb6594181933e; 2014-06-17T09:51:42-04:00)
Maven home: C:\dev\bin\apache-maven-3.2.2
Java version: 1.8.0_11, vendor: Oracle Corporation
Java home: C:\progra~1\java\jdk1.8.0_11\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "dos"
Questions:
Why is this failing / how to fix?
Why is this failing when parent is added? How is exec-maven-plugin influenced by this?
(As a side note, I love the fact that Windows 7 belongs to faimly: "dos", I'm waiting for family: "cp/m" to be implemented for Windows 8.1)
Its because Spring-Boot is adding some extra maven configuration to your project.
If you are using eclipse, there's a Tab called: 'Effective POM'.
From this tab you can see that it adds this snippet below:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>${start-class}</mainClass>
</configuration>
</plugin>
So when you run it with spring-boot as parent, it looks for the value of ${start-class}, which resolves to empty unless you defined it, that's when you see the error about not having a value for the mainClass parameter.
Add this to your project:
<properties>
<start-class>com.Test</start-class>
</properties>
Then run it: clean compile exec:java
[INFO] --- exec-maven-plugin:1.2.1:java (default-cli) # springboot-test ---
**********test**************
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.388 s
[INFO] Finished at: 2014-12-05T15:25:05-06:00
[INFO] Final Memory: 17M/231M
[INFO] ------------------------------------------------------------------------
You can also provide the value for the start-class property on the command line, this works even if you didn't define it inside your pom file:
mvn exec:java -Dstart-class=com.Test
I am trying to execute below sparkSQL example,
https://github.com/apache/spark/blob/master/examples/src/main/java/org/apache/spark/examples/sql/JavaSparkSQL.java
my pom.xml (i have added sql dependency as well, i am stuck please help)
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>edu.berkeley</groupId>
<artifactId>simple-project</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>Simple Project</name>
<repositories>
<repository>
<id>Akka repository</id>
<url>http://repo.akka.io/releases</url>
</repository>
</repositories>
<dependencies>
<dependency> <!-- Spark dependency -->
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.10</artifactId>
<version>1.0.2</version>
</dependency>
<dependency> <!-- Spark dependency -->
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.10</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies>
</project>
i have just renamed the file as SimpleApp.java
I get this following error when compiling.. kindly advice
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Simple Project 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # simple-project ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Volumes/Official/spark-1.0.2-bin-hadoop2/try/simple-project/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) # simple-project ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /Volumes/Official/spark-1.0.2-bin-hadoop2/try/simple-project/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Volumes/Official/spark-1.0.2-bin-hadoop2/try/simple-project/src/main/java/SimpleApp.java:[61,16] error: cannot find symbol
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.801 s
[INFO] Finished at: 2014-08-19T10:30:31+05:30
[INFO] Final Memory: 21M/232M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project simple-project: Compilation failure
[ERROR] /Volumes/Official/spark-1.0.2-bin-hadoop2/try/simple-project/src/main/java/SimpleApp.java:[61,16] error: cannot find symbol
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
I found out the issue:
In the example
https://github.com/apache/spark/blob/master/examples/src/main/java/org/apache/spark/examples/sql/JavaSparkSQL.java
replace the line schemaPeople.registerTempTable("people");
with schemaPeople.registerAsTable("people");
compile and package with mvn compile and mvn package and run with
bin/spark-submit --class "org.apache.spark.examples.sql.SimpleApp" --master local[4] try/simple-project/target/simple-project-1.0.jar
I wanted to add a test to my small project (please note I removed some bits from the code & changed package names, so if there's any error you see regarding this it might be not this ;)):
package my.pckg;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class SignedRequestCallbackTest {
#Before
public void setUp() throws Exception {
}
#After
public void tearDown() throws Exception {
}
#Test
public void testCorrectSignedRequest() {
assertTrue(false);
}
}
(I also tried to extend from TestCase in order to remove the static import but it didn't help)
After running mvn test it shows me an error that it couldn't find org.junit:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Test Server 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) # server ---
[WARNING] Using platform encoding (MacRoman actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) # server ---
[WARNING] File encoding has not been set, using platform encoding MacRoman, i.e. build is platform dependent!
[INFO] Compiling 9 source files to /Users/michael/Projects/fbmuc/server/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[4,27] package org.junit does not exist
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[6,16] package org.junit does not exist
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[7,16] package org.junit does not exist
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[8,16] package org.junit does not exist
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[14,9] cannot find symbol
symbol : class Before
location: class my.pckgSignedRequestCallbackTest
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[18,9] cannot find symbol
symbol : class After
location: class my.pckgSignedRequestCallbackTest
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[22,9] cannot find symbol
symbol : class Test
location: class my.pckgSignedRequestCallbackTest
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[24,12] cannot find symbol
symbol : method assertTrue(boolean)
location: class my.pckgSignedRequestCallbackTest
[INFO] 9 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.161s
[INFO] Finished at: Fri Feb 22 18:02:37 CET 2013
[INFO] Final Memory: 8M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project server: Compilation failure: Compilation failure:
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[4,27] package org.junit does not exist
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[4,4] static import only from classes and interfaces
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[6,16] package org.junit does not exist
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[7,16] package org.junit does not exist
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[8,16] package org.junit does not exist
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[14,9] cannot find symbol
[ERROR] symbol : class Before
[ERROR] location: class my.pckgSignedRequestCallbackTest
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[18,9] cannot find symbol
[ERROR] symbol : class After
[ERROR] location: class my.pckgSignedRequestCallbackTest
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[22,9] cannot find symbol
[ERROR] symbol : class Test
[ERROR] location: class my.pckgSignedRequestCallbackTest
[ERROR] ~/code/src/test/java/my/pckg/SignedRequestCallbackTest.java:[24,12] cannot find symbol
[ERROR] symbol : method assertTrue(boolean)
[ERROR] location: class my.pckgSignedRequestCallbackTest
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
My pom.xml looks like this:
<?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.example</groupId>
<artifactId>server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>TestServer</name>
<description>Test</description>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- Facebook library -->
<dependency>
<groupId>com.restfb</groupId>
<artifactId>restfb</artifactId>
<version>1.6.11</version>
</dependency>
<!-- Gson: Java to Json conversion -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.2</version>
<scope>compile</scope>
</dependency>
<!-- Tigase server snapshot -->
<dependency>
<groupId>tigase</groupId>
<artifactId>tigase-server</artifactId>
<version>5.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>tigase</id>
<name>Tigase repository</name>
<url>http://maven.tigase.org</url>
</repository>
<repository>
<id>tigase-snapshot</id>
<name>Tigase repository</name>
<url>http://build.xmpp-test.net/maven/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</project>
mvn dependency:tree:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Test Server 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) # server ---
[INFO] my.pckg:server:jar:0.0.1-SNAPSHOT
[INFO] +- com.restfb:restfb:jar:1.6.11:compile
[INFO] +- com.google.code.gson:gson:jar:2.2.2:compile
[INFO] +- tigase:tigase-server:jar:5.2.0-SNAPSHOT:compile
[INFO] | +- tigase:tigase-utils:jar:3.4.1-SNAPSHOT:compile
[INFO] | \- tigase:tigase-xmltools:jar:3.4.3-SNAPSHOT:compile
[INFO] +- commons-codec:commons-codec:jar:1.7:compile
[INFO] \- junit:junit:jar:4.11:test
[INFO] \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.240s
[INFO] Finished at: Fri Feb 22 18:07:55 CET 2013
[INFO] Final Memory: 5M/81M
[INFO] ------------------------------------------------------------------------
mvn version:
Apache Maven 3.0.3 (r1075438; 2011-02-28 18:31:09+0100)
Maven home: /usr/share/maven
Java version: 1.6.0_41, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: de_CH, platform encoding: MacRoman
OS name: "mac os x", version: "10.8.2", arch: "x86_64", family: "mac"
Please note that I'm not an expert in java nor in maven, just getting started (especially with maven).
From what I've seen from other articles and questions, I should have my tests within src/test/java and my "real" code within src/main/java - I have done it like this.
Also I removed once the whole ~/.m2/ folder and it still didn't work.
I also did run mvn test -X but it didn't help me. If I should post it please tell me so.
You shouldn't override your <sourceDirectory> setting in the POM's <build> element unless you have a good reason to. This attribute determines where Maven looks for non-test code. The default value for this attribute is src/main/java. The <testSourceDirectory> attribute sets the path to test code (this defaults to src/test/java. By setting the <sourceDirectory> to simply src, Maven considers that entire directory to contain main application code. Since the src directory contains src/test/java, Maven then tries to compile your test code as part of the main application.
This is significant because when compiling the main application (during the compile phase), Maven omits dependencies with test scope. Test code is compiled in a separate phase (the test-compile phase) after the main compile.
So since Maven tried to compile your test code as part of the main application, it omitted the junit dependency, and they weren't available on the classpath. The solution here is to simply not specify the <sourceDirectory> element in the POM.
By default , maven looks at these folders for java and test classes respectively - src/main/java and src/test/java
When the src is specified with the test classes under source and the scope for junit dependency in pom.xml is mentioned as test - org.unit will not be found by maven.
Just putting image to #matts Answer, so its easy for other to correct the problems.
<sourceDirectory>src</sourceDirectory>
just delete or comment this line present in pom.xml
<!-- <sourceDirectory>src</sourceDirectory> !-->
For explanation please go through #matt's answer