PROJECT-A is a war. It has some code I want to use in the unit tests of PROJECT-B.
To do this, I think I need PROJECT-A to output a jar with it's classes. Here is an excerpt of the POM:
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<parent>
<groupId>au.com.name.redacted</groupId>
<artifactId>PARENT-PROJECT</artifactId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>PROJECT-A</artifactId>
<packaging>war</packaging>
... snip
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>PROJECT-A-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
When I run
cd PROJECT-A
mvn clean install
it outputs
[INFO] --- maven-jar-plugin:2.4:jar (PROJECT-A-jar) # PROJECT-A ---
[INFO] Building jar: D:\Workspace\name\PROJECT-A\target\PROJECT-A-1.0.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) # PROJECT-A ---
[INFO] Installing D:\Workspace\name\PROJECT-A\target\PROJECT-A-1.0.jar to C:\Users\myusername\.m2\repository\au\com\name\PARENT-PROJECT\PROJECT-A\1.0\PROJECT-A-1.0.war
I do see
D:\Workspace\name\PROJECT-A\target\PROJECT-A-1.0.jar
D:\Workspace\name\PROJECT-A\target\PROJECT-A-1.0.war
but I do not see the jar in in my repo - only the war.
C:\Users\myusername\.m2\repository\au\com\name\PARENT-PROJECT\PROJECT-A\1.0\PROJECT-A-1.0.war
So then in PROJECT-B I am attempting to have it get PROJECT-A as a dependency..
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<parent>
<groupId>au.com.name.redacted</groupId>
<artifactId>PARENT-PROJECT</artifactId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>PROJECT-B</artifactId>
<packaging>war</packaging>
... snip
<dependency>
<groupId>au.com.name.redacted</groupId>
<artifactId>PROJECT-A</artifactId>
<version>1.0</version>
<scope>test</scope>
</dependency>
And it fails with
[ERROR] Failed to execute goal on project PROJECT-B: Could not resolve dependencies for project au.com.name.redacted:PROJECT-B:war:1.0: Failure to find au.com.name.redacted:PROJECT-A:jar:1.0 in http://repo.server.com.au:8081/artifactory/repo was cached in the local repository, resolution will not be reattempted until the update interval of repo has elapsed or updates are forced -> [Help 1]
I've used war plugin for this purpose. Maybe this will help:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<attachClasses>true</attachClasses>
</configuration>
</plugin>
It generates war and jar with sources after build which will be commited to local m2 repo. Configuration <attachClasses>true</attachClasses> is important.
In pom of project B use something like this (important part - <classifier>classes</classifier>):
<dependency>
<groupId>projectA-groupid</groupId>
<artifactId>projectA-artifactId</artifactId>
<version>projectA-version</version>
<classifier>classes</classifier>
</dependency>
Related
I am trying to generate an aggregate Jacoco code coverage report by following the steps here.
My initial maven project may contain multiple modules and I add an aggregator module aggregator to the main pom dynamically through my code.
The folder structure looks somewhat like this (there can be any number of modules and sub modules in the main project):
/SampleProject/
-- pom.xml
-- module1/
---- pom.xml
---- src/
-- module2/
---- pom.xml
---- src/
-- module3/
---- pom.xml
---- src/
-- aggregator/
---- pom.xml
This is the main pom:
SampleProject/pom.xml . (here, the aggregator module is added dynamically through my code)
<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>com.sample</groupId>
<artifactId>sampleProject</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>sampleProject</name>
<modules>
<module>module1</module>
<module>module2</module>
<module>module3</module>
<module>aggregator</module>
</modules>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Each module has its own pom.xml. and the aggregator pom (which is generated by my code) looks something like this (each module is added as a dependency in this pom. This information is fetched from the individual poms of the modules):
aggregator/pom.xml
<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>
<parent>
<groupId>com.sample</groupId>
<artifactId>sampleProject</artifactId>
<version>1.0</version>
</parent>
<artifactId>aggregator</artifactId>
<dependencies>
<dependency>
<groupId>com.sample.module1</groupId>
<artifactId>module1</artifactId>
<version>0.1</version>
</dependency>
<dependency>
<groupId>com.sample.module2</groupId>
<artifactId>module2</artifactId>
<version>0.1</version>
</dependency>
<dependency>
<groupId>com.sample.module3</groupId>
<artifactId>module3</artifactId>
<version>0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<argLine>${argLine} -Xms256m -Xmx2048m</argLine>
<forkCount>1</forkCount>
<runOrder>random</runOrder>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
<execution>
<id>report-aggregate</id>
<phase>test</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
and, to generate the aggregate report I use the following command:
mvn clean test -DskipTests=false
This generates the aggregate report in 'aggregator/target/site/jacoco-aggregate/index.html'
Now, the problem is if something goes wrong with only the aggregator build, and that build fails (but all other modules' build is successful). Then the maven output will look something like this:
[INFO] module1 .......................................... SUCCESS [ 2.197 s]
[INFO] module2 .......................................... SUCCESS [ 11.287 s]
[INFO] module3 .......................................... SUCCESS [ 6.969 s]
[INFO] aggregator ....................................... FAILURE [ 1.241 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 00:21 min
[INFO] Finished at: 2018-07-26T13:01:12-07:00
[INFO] Final Memory: 258M/1149M
Which means that the overall build is also marked as failed if just the aggregator part fails. This causes problem in the next step in the deployment pipeline.
So, what I want is that even if the aggregator build is failing, the overall build should be marked as passed (i.e. ignore the failing aggregator build) so that I can proceed with the next step in deployment, so that not generating the code coverage report, does not fail my entire deployment process. (I will handle the missing code coverage report later in the process).
Is there some way to achieve this? any help would be appreciated.
UPDATE 1:
I already check this answer and this is not what I want. Using -fae flag in maven would still mark the build as failed at the end.
Also, I do not want the -fn flag either because then I would be ignoring actual build failures in the modules as well, which is not desired.
What I'm looking for is a way to ignore the failures of just one module in maven.
I'm not really sure if doing that is possible, any alternate suggestions are welcome too.
UPDATE 2:
Update and some background info.:
So, I am building this tool as kind of a central tool which runs on all projects so it should be generic enough to cater to different types of configurations, without changing anything in the main project (on which the tests are being run).
As of now, it seems what I am looking for is not possible. So, as a workaround, I am asking the main project's owner to include a config file which tells my tool which packages to be included for code coverage.
Will update here if I find a better solution or workaround.
I have a project. Originally it was a single module project with structure like this
java-cloud-sample\
src\
main\
java
pom.xml
I decided to make it into a multi-module structure - I use java 9 anyway.
So I separated it like this
java-cloud-sample\
java-cloud-rest-api\
src\
pom.xml
pom.xml
Where root 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.lapots.breed.platform.cloud</groupId>
<artifactId>java-cloud-sample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>java-cloud-rest-api</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.9</maven.compiler.source>
<maven.compiler.target>1.9</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals><goal>copy-dependencies</goal></goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
And module 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>
<parent>
<groupId>com.lapots.breed.platform.cloud</groupId>
<artifactId>java-cloud-sample</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>java-cloud-rest-api</artifactId>
<description>Demo project for Spring Boot</description>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
<configuration>
<additionalProperties>
<encoding.source>${project.build.sourceEncoding}</encoding.source>
<encoding.reporting>${project.reporting.outputEncoding}</encoding.reporting>
<java.source>${maven.compiler.source}</java.source>
<java.target>${maven.compiler.target}</java.target>
</additionalProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
But when I try to run mvn clean package I get
INFO] java-cloud-rest-api ................................ FAILURE [ 1.060 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.104 s
[INFO] Finished at: 2017-09-08T17:15:46+03:00
[INFO] Final Memory: 27M/331M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.2:compile (default-compile) on project java-cloud-rest-api: Fatal error compiling: invalid flag: --module-path -> [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
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <goals> -rf :java-cloud-rest-api
What is the problem? (maybe I should split maven project into separate modules and each maven module split into java modules)
This failure occurs when maven installed on your machine is configured with java8 as the default java version. You can confirm this by executing
mvn -version
on your terminal and checking the Java version stated in the configuration.
To resolve the version to a newer and supported version like java9 at the moment, you can create/edit the mavenrc(on MacOS) file on your machine:
vi ~/.mavenrc
to include these
export PATH
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home/
export PATH=${PATH}:$JAVA_HOME/bin
Once you save this configuration, you can confirm maven should be using Java version 9 using the same command and then your project shall build without the stated error.
I had this error with the Maven compiler plugin 3.8.1 when a project was defining a module-info.java and Java 8 was used with Maven to compile the project. It seems that as soon a module-info.java is seen by the Maven compiler plugin it is adding the flag --module-path to the command line which is unknown to the Java 8 compiler. A way to exclude this file and compile the project without module support is to exclude the module-info.java from compilation based on a Maven profile:
<profiles>
<profile>
<id>java8</id>
<activation>
<jdk>1.8</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<excludes>
<exclude>module-info.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Goal: Create an executable uber jar with maven shade plugin that can be executed during the mvn compile of another pom.
Repro steps:
Create a pom.xml for the "publisher" component using below pom.
Use a Jenkins build to mvn deploy it (mvn install will work as well)
Add dependency to pom.xml for "consumer" (pom below)
mvn compile the consumer
Expected behavior:
Uber jar for publisher is downloaded somewhere in consumer/target directories
Actual:
Uber jar does not appear in consumer directory
Component 1: Publisher
<?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.mec.experiment</groupId>
<artifactId>publisher</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.6.Final</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestFile>src/main/resources/META-INF/MANIFEST.mf</manifestFile>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Component 2: Consumer
<?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.mec.experiment</groupId>
<artifactId>consumer</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.mec.experiment</groupId>
<artifactId>publisher</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
The answer from the possible duplicate I linked to in the comments has a link to a dead example page. Here's a supplement for you. The plugin configuration would belong inside the consumer pom.
exec:java
Full name:
org.codehaus.mojo:exec-maven-plugin:1.5.0:java
Description:
Executes the supplied java class in the current VM with the enclosing project's dependencies as classpath.
Attributes:
Requires a Maven project to be executed.
Requires dependency resolution of artifacts in scope: test.
The goal is thread-safe and supports parallel builds.
Since version: 1.0.
See especially executableDependency for your use case. That looks like it will allow you to reference producer according to its group id and artifact instead of hard-coding a path.
I am creating a maven project from scratch, first just learn how to use maven.
The main project contains no source code file, but it has two modules (app, and util). App depends on util. I would like to have a .jar from app, and have no manifest file if possible.
I am able to compile the whole project with mvn clean install, but can not run the app from console.
The main project .pom 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.proba</groupId>
<artifactId>myproject</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>
<modules>
<module>util</module>
<module>app</module>
</modules>
</project>
Util .pom is
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.proba</groupId>
<artifactId>myproject</artifactId>
<version>0.0.1</version>
</parent>
<artifactId>util</artifactId>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
app pom is
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.proba</groupId>
<artifactId>myproject</artifactId>
<version>0.0.1</version>
</parent>
<artifactId>app</artifactId>
<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>com.proba</groupId>
<artifactId>util</artifactId>
<version>0.0.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>com.proba.app.App</mainClass>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<phase>site-deploy</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.proba.app.App</mainClass>
<!--<arguments> <argument>myArg1</argument> <argument>myArg2</argument>
</arguments> -->
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
The code doesn't do too much.
App.java (that inside the app module) is
package com.proba.app;
import com.proba.util.UtilClass;
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
UtilClass uc = new UtilClass();
System.out.println( "QQQQQ: " + uc.print() );
}
}
I compile it with
mvn clean install
[INFO] Reactor Summary:
[INFO]
[INFO] myproject .......................................... SUCCESS [ 0.406 s]
[INFO] util ............................................... SUCCESS [ 2.074 s]
[INFO] app ................................................ SUCCESS [ 0.535 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
myproject, util, app is SUCCESS.
I try to run it with
java -jar app/target/app-0.0.1.jar
Hello World!
Exception in thread "main" java.lang.NoClassDefFoundError: com/proba/util/UtilClass
at com.proba.app.App.main(App.java:17)
Caused by: java.lang.ClassNotFoundException: com.proba.util.UtilClass
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
As you can see, Hello World! is printed out, but UtilClass is not found.
I am able to run the build from eclipse, but not from the console.
What I am doing wrong? Do you have any idea?
What you missing is the jar of UtilClass. You just need to add shade plugin in your pom.
As reference: maven-shade-plugin
In the pom.xml of app module,You have writtent the compile thats why at runtime your jar is not getting into the classpath.Remove the compile line.And it will work.
Util.jar is added to your app pom.xml as dependency but the scope is compile. So it is not getting added to your Manifest as classpath entry. Remove scope element and then try.
This question already has answers here:
Maven - add dependency on artifact source
(2 answers)
Closed 8 years ago.
I would like to add a source jar to a gwt project using maven.
I tried to do it this way (it's just a poc for managing source dependencies)
source jar pom :
<?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">
<parent>
<artifactId>test-source-dependencies</artifactId>
<groupId>com.niflheimcorp</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>test-source-jar</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
using jar pom :
<?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.niflheimcorp</groupId>
<artifactId>test-utilisateur-jar</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.niflheimcorp</groupId>
<artifactId>test-source-jar</artifactId>
<classifier>source</classifier>
</dependency>
</dependencies>
</project>
when launching mvn clean install i got the following error :
[ERROR] Failed to execute goal on project test-utilisateur-jar: Could not resolv
e dependencies for project com.niflheimcorp:test-utilisateur-jar:jar:1.0-SNAPSHO
T: Could not find artifact com.niflheimcorp:test-source-jar:jar:source:1.0-SNAPS
HOT -> [Help 1]
But the artifact is installed by maven just at the precedent step
[INFO] Installing C:\Users\CRSD2193\psf\G4R0C3_portaFixe\test-sources-dependenci
es\test-source-jar\target\test-source-jar-1.0-sources.jar to C:\Users\CRSD2193.
m2\repository\com\niflheimcorp\test-source-jar\1.0\test-source-jar-1.0-sources.j
ar
I can't see a reason for the error unless we can't declare a source jar as a build deps.
Regards
Nemesis
Dumb typo on the classifier sources (forgot the s at the end :-/ ).