run maven plugin goal on multiple modules - java

So I have many maven modules in my project and I'd like to run one maven plugin's goal on multiple modules
Here's what I do:
mvn -pl module1,module2,module3 wls:deploy
Unfortunately here's what I get:
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] module1 ............................................... SUCCESS [7.422s]
[INFO] module2 ............................................... SKIPPED
[INFO] module3 ............................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.370s
[INFO] Finished at: Thu Jul 02 09:34:37 CEST 2015
[INFO] Final Memory: 23M/301M
[INFO] ------------------------------------------------------------------------
So the problem is that maven SKIPS all the modules after the first one, and I'd like the goal to be fired on all modules.
This is what I'd like to achieve:
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] module1 ............................................... SUCCESS [7.422s]
[INFO] module2 ............................................... SUCCESS [12.674s]
[INFO] module3 ............................................... SUCCESS [4.563s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.370s
[INFO] Finished at: Thu Jul 02 09:34:37 CEST 2015
[INFO] Final Memory: 23M/301M
[INFO] ------------------------------------------------------------------------
The plugin I use is:
<groupId>com.oracle.weblogic</groupId>
<artifactId>wls-maven-plugin</artifactId>
<version>12.1.1.0</version>
How to make maven run the goal on both modules?

Use maven submodule functionality, example from internet for weather and webapp modules
<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>org.sonatype.mavenbook.multi</groupId>
<artifactId>simple-parent</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<name>Multi Chapter Simple Parent Project</name>
<modules>
<module>simple-weather</module>
<module>simple-webapp</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<profiles>
<profile>
<id>ci</id>
<modules>
<module>simple-weather</module>
<module>simple-webapp</module>
</modules>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Then mvn -pl simple-parent wls:deploy

Related

Why does resolved dependencies differ between Java 8 and Java 11?

Given a very simple Maven project with a single pom-file containing a single dependency:
<?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>org.example</groupId>
<artifactId>maven-test</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.apache.cxf.xjc-utils</groupId>
<artifactId>cxf-xjc-runtime</artifactId>
<version>3.3.0</version>
</dependency>
</dependencies>
</project>
When running mvn dependency:tree different results are given depending on Java version.
With Java 8:
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< org.example:maven-test >-----------------------
[INFO] Building maven-test 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # maven-test ---
[INFO] org.example:maven-test:jar:1.0-SNAPSHOT
[INFO] \- org.apache.cxf.xjc-utils:cxf-xjc-runtime:jar:3.3.0:compile
[INFO] \- jakarta.xml.bind:jakarta.xml.bind-api:jar:2.3.2:compile
[INFO] \- jakarta.activation:jakarta.activation-api:jar:1.2.1:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.982 s
[INFO] Finished at: 2020-06-22T15:05:56+02:00
[INFO] ------------------------------------------------------------------------
With Java 11:
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< org.example:maven-test >-----------------------
[INFO] Building maven-test 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # maven-test ---
[INFO] org.example:maven-test:jar:1.0-SNAPSHOT
[INFO] \- org.apache.cxf.xjc-utils:cxf-xjc-runtime:jar:3.3.0:compile
[INFO] +- jakarta.xml.bind:jakarta.xml.bind-api:jar:2.3.2:compile
[INFO] | \- jakarta.activation:jakarta.activation-api:jar:1.2.1:compile
[INFO] +- javax.annotation:javax.annotation-api:jar:1.3.1:compile <-- This and below only with Java 11
[INFO] +- javax.xml.ws:jaxws-api:jar:2.3.0:compile
[INFO] | +- javax.xml.bind:jaxb-api:jar:2.3.0:compile
[INFO] | \- javax.xml.soap:javax.xml.soap-api:jar:1.4.0:compile
[INFO] \- javax.activation:activation:jar:1.1.1:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.261 s
[INFO] Finished at: 2020-06-22T15:05:51+02:00
[INFO] ------------------------------------------------------------------------
I would have expected the trees to be the same under the two Java versions.
Maven version is 3.6.0.
Why do the resolved dependencies differ between the Java versions?
The reason why the dependency tree differs between the Java versions is found in the dependency:
<dependency>
<groupId>org.apache.cxf.xjc-utils</groupId>
<artifactId>cxf-xjc-runtime</artifactId>
<version>3.3.0</version>
</dependency>
This in turn has xjc-utils as its parent:
<parent>
<groupId>org.apache.cxf.xjc-utils</groupId>
<artifactId>xjc-utils</artifactId>
<version>3.3.0</version>
</parent>
In this POM file, we find the dependencies that are excluded when building with Java 8:
<profile>
<id>java9-plus</id>
<activation>
<jdk>[9,)</jdk>
</activation>
<dependencies>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
</profile>
This pretty much speacks for itself, the dependencies will only be included if Java 9 or above is used, as stated in this range: <jdk>[9,)</jdk>. The documentation for the tag states:
Specifies that this profile will be activated when a matching JDK is detected. For example, 1.4 only activates on JDKs versioned 1.4, while !1.4 matches any JDK that is not version 1.4.
This activation profile makes sure these dependencies are included when Java 11 is used:
[INFO] +- javax.annotation:javax.annotation-api:jar:1.3.1:compile
[INFO] +- javax.xml.ws:jaxws-api:jar:2.3.0:compile
[INFO] | +- javax.xml.bind:jaxb-api:jar:2.3.0:compile
[INFO] | \- javax.xml.soap:javax.xml.soap-api:jar:1.4.0:compile
[INFO] \- javax.activation:activation:jar:1.1.1:compile
More info about activation can be found in the official Maven documentation:
Activations are the key of a profile. The power of a profile comes from its ability to modify the basic POM only under certain circumstances. Those circumstances are specified via an activation element.
Together with another example of activation based on Java version:
<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">
...
<profiles>
<profile>
<id>test</id>
<activation>
<activeByDefault>false</activeByDefault>
<jdk>1.5</jdk>
<os>
<name>Windows XP</name>
<family>Windows</family>
<arch>x86</arch>
<version>5.1.2600</version>
</os>
<property>
<name>sparrow-type</name>
<value>African</value>
</property>
<file>
<exists>${basedir}/file2.properties</exists>
<missing>${basedir}/file1.properties</missing>
</file>
</activation>
...
</profile>
</profiles>
</project>
Dependency tree mojo trims lower level dependencies if the dependency is already present higher in the tree.
We can use verbose flag (-Dverbose) to show the excluded dependencies.
To find a specific artifact : mvn dependency:tree -Dverbose -Dincludes=[groupId]:[artifactId]:[type]:[version]
Please visit Maven Dependency Tree to know more.

Maven Pom.xml not running

I try to run my test as -mvn test, it is showing as build is success but , No Source to Compile.Down I have attached my both pom and Result file.
Output :
[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Wepaythemax 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # Wepaythemax ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\rck\git\repository3\Wepaythemax\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) # Wepaythemax ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # Wepaythemax ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) # Wepaythemax ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # Wepaythemax ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.051 s
[INFO] Finished at: 2018-12-20T18:37:53+05:30
[INFO] Final Memory: 10M/114M
Pom.xml File
<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>Wepaythemax</groupId>
<artifactId>Wepaythemax</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>3.141.5</version>
</dependency>
</dependencies>
<profiles>
<profile>
<id>selenium-tests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Help Me out, Where I have done Mistake, I can't find out. I'm Trying to Figure it out.Also I have attached a Screenshot Where the My testng.xml file is placed
no sources to compile, means no java file in src/main/java or src/test/java.
sources are in src/main/java, sources is different from resources, which means .xml,etc.

Maven Version Issues

I am trying to test a maven project but i keep getting this error...any ideas?
My Java version is "1.7.0_80"
All suggestions are welcomed..
/usr/lib/jvm/java-7-oracle/bin/java -Dmaven.home=/usr/share/maven2 -Dclassworlds.conf=/usr/share/maven2/bin/m2.conf -Didea.launcher.port=7541 -Didea.launcher.bin.path=/opt/idea/bin -Dfile.encoding=UTF-8 -classpath /usr/share/maven2/boot/classworlds.jar:/opt/idea/lib/idea_rt.jar com.intellij.rt.execution.application.AppMain org.codehaus.classworlds.Launcher -Didea.version=13.1.4 --no-plugin-registry test
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - com.rancard.kudi:kudi-client:jar:1.0-SNAPSHOT
[INFO] task-segment: [test]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources {execution: default-resources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error building POM (may not be this project's POM).
Project ID: org.glassfish.jersey:project
Reason: Invalid JDK version in profile 'jdk1.7+': Unbounded range: [1.7, for project org.glassfish.jersey:project
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Thu Jul 30 12:42:53 GMT 2015
[INFO] Final Memory: 14M/172M
[INFO] ------------------------------------------------------------------------
Process finished with exit code 1
This is the result when I build from the command line...it flags the same error...
rancard#RSL-PROD-INT1 ~/IdeaProjects/kudi/client $ mvn package
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - com.rancard.kudi:kudi-client:jar:1.0-SNAPSHOT
[INFO] task-segment: [package]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources {execution: default-resources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error building POM (may not be this project's POM).
Project ID: org.glassfish.jersey:project
Reason: Invalid JDK version in profile 'jdk1.7+': Unbounded range: [1.7, for project org.glassfish.jersey:project
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5 seconds
[INFO] Finished at: Thu Jul 30 15:35:39 GMT 2015
[INFO] Final Memory: 14M/108M
[INFO] ------------------------------------------------------------------------
This is the content of my pom 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">
<parent>
<artifactId>kudi-platform</artifactId>
<groupId>com.rancard.kudi</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>kudi-client</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.rancard.kudi</groupId>
<artifactId>kudi-domain</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.bundles</groupId>
<artifactId>jaxrs-ri</artifactId>
<version>2.19</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.19</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.19</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
</plugin>
</plugins>
</build>
</project>
My guess is that the pom of the glassfish jersey dependency has a profile that is activated when a certain jdk version is used. But the declaration of the JDK version is malformed.
See below : (http://central.maven.org/maven2/org/glassfish/jersey/project/2.19/project-2.19.pom)
<profile>
<id>jdk1.7+</id>
<activation>
<jdk>[1.7,</jdk>
</activation>
...
</profile>
I had the same issue when maven 2.0.6 was installed.
Run mvn -version and check you have the right maven version, it should look like this:
Apache Maven 3.0.4
Maven home: /usr/share/maven

Maven: package org.junit does not exist

I'm new to Maven, so excuse me if this is so elemental. I have searched about this problem, and everyone seems to solve it removing the tag from the pom.xml file.
I do not have that tag there:
<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>GraphApp</groupId>
<artifactId>GraphApp</artifactId>
<version>1.0.0</version>
<name>MyApp</name>
<description>MyApp</description>
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
I have converted an existing project with Eclipse, so the problem may come from that.
Also, I have read that the default schema for Maven is storing the code at some default folders, while I'm using src/com/romanrdgz/core/myapp and /test/com/romanrdgz/test/core. That could also be the origin of the problem.
I am seeing this error:
Maven: package org.junit does not exist
What do I need to change?
EDIT: Ok, I have included JUnit4 as dependency, and I have also changed my file folders to be like this:
Still, when I go to console and execute mvn test or mvn compile, I get the following output:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building GraphApp 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # GraphApp -
--
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\rrrp\workspace\GraphApp\src\
main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # GraphApp ---
[INFO] Nothing to compile - all classes are up to date
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.515 s
[INFO] Finished at: 2015-04-15T08:15:06+02:00
[INFO] Final Memory: 11M/309M
[INFO] ------------------------------------------------------------------------
I tried erasing bin and target folders, but still the same. Looks like it does not find the classes nor the tests.
Any help?
Add the junit dependency to the pom file in a dependencies section
<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">
.....
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
</dependencies>
</project>

Maven: Combining multiple module jars into one war file?

I have a project babybird which has 3 components persistence, business and service
in babybird's pom.xml I have following
<modules>
<module>persistence</module>
<module>business</module>
<module>service</module>
</modules>
when I run mvn clean install, I see
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] babybird ......................................... SUCCESS [2.801s]
[INFO] persistence ....................................... SUCCESS [3.321s]
[INFO] business .......................................... SUCCESS [0.832s]
[INFO] service ........................................... SUCCESS [0.694s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.168s
[INFO] Finished at: Tue Jan 22 12:09:48 PST 2013
[INFO] Final Memory: 18M/50M
[INFO] ------------------------------------------------------------------------
and each one of these modules generate a jar file.
Question: How can I combine them into one babybird.war?
I am new to Maven and do not know what to look for to accomplish this task, please provide the pointers
That's fairly simple. Create another module named web or similar:
<modules>
<module>persistence</module>
<module>business</module>
<module>service</module>
<module>web</module>
</modules>
web module should depend on all others:
<dependencies>
<dependency>
<groupId>...</groupId>
<artifactId>persistence</artifactId>
</dependency>
...
</dependencies>
and have war packaging:
<packaging>war</packaging>
You'll also need web.xml in /src/main/webapp/WEB-INF. That's it.

Categories

Resources