Change maven dependency for artifact using classifier - maven-2

With the maven jar plugin I build two jar: bar-1.0.0.jar and bar-1.0.0-client.jar.
Actually in my POM I have the following dependency:
<dependency>
<groupId>de.app.test</groupId>
<artifactId>foo</artifactId>
<version>1.0.0</version>
</dependency>
This artifact exist also in two version bar-1.0.0.jar and bar-1.0.0-client.jar
I want to make bar-1.0.0-client.jar dependent of foo-1.0.0-client.jar and bar-1.0.0.jar dependent of foo-1.0.0.jar.
================
->First (wrong) solution: define the scope as provided and use the right foo package when using bar.jar
->Second (long) solution : Add 'server' classifier to the other jar. Use different profile to build the foo artifact and put the classifier in a property.
<dependency>
<groupId>de.app.test</groupId>
<artifactId>foo</artifactId>
<version>1.0.0</version>
<classifier>${profile.classifier}<classifier>
</dependency>
================
Concerning the profile solution.
Interfaces module pom
<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">
<parent>
<groupId>com.app</groupId>
<artifactId>myapp-parent</artifactId>
<version>1.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.app</groupId>
<artifactId>myapp-interfaces</artifactId>
<version>1.1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>myapp Interfaces</name>
<profiles>
<profile>
<id>server</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>jar-server</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>server</classifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>client</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>jar-client</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>client</classifier>
<excludes>
<exclude>**/server/**</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Implementation module pom
<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">
<parent>
<groupId>com.app</groupId>
<artifactId>myapp-parent</artifactId>
<version>1.1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.app</groupId>
<artifactId>myapp-model</artifactId>
<version>1.1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>myapp Model</name>
<properties>
<myapp-interfaces.classifier></myapp-interfaces.classifier>
<myapp-interfaces.version>1.1.0-SNAPSHOT</myapp-interfaces.version>
</properties>
<dependencies>
<dependency>
<groupId>com.app</groupId>
<artifactId>myapp-interfaces</artifactId>
<version>${myapp-interfaces.version}</version>
<classifier>${myapp-interfaces.classifier}</classifier>
</dependency>
[...]
</dependencies>
<profiles>
<profile>
<id>server</id>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>jar-server</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>server</classifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.app</groupId>
<artifactId>myapp-interfaces</artifactId>
<version>${myapp-interfaces.version}</version>
<classifier>${myapp-interfaces.classifier}</classifier>
</dependency>
</dependencies>
<properties>
<myapp-interfaces.classifier>server</myapp-interfaces.classifier>
</properties>
</profile>
<profile>
<id>client</id>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>jar-client</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>client</classifier>
<excludes>
<exclude>**/server/**</exclude>
<exclude>**/META-INF/services/**</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<myapp-interfaces.classifier>client</myapp-interfaces.classifier>
</properties>
<dependencies>
<dependency>
<groupId>com.app</groupId>
<artifactId>myapp-interfaces</artifactId>
<version>${myapp-interfaces.version}</version>
<classifier>${myapp-interfaces.classifier}</classifier>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
The problem with this solution is due to the fact that my client interface have some missing interfaces and maven throw a compilation error during the compile phase.
And if I use myapp-model and an other project I didn't not have dependency to the right myapp-interface.
I wonder if it's possible to build a jar and put a specific pom inside ?

For the Interfaces.
I change nothing and build the both interfaces.jar (client + server).
For the Model
I import the both jar as optional
<dependency>
<groupId>com.app</groupId>
<artifactId>myapp-interfaces</artifactId>
<version>${myapp-interfaces.version}</version>
<classifier>client</classifier>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.app</groupId>
<artifactId>myapp-interfaces</artifactId>
<version>${myapp-interfaces.version}</version>
<classifier>server</classifier>
<optional>true</optional>
</dependency>
With that I can build the both model's version without any error.
In my client application and server application
For each application I create the dependency to the right interfaces.jar and models.jar

Related

Intellij gives incompatible kotlin version but no kotlin is used

I'm trying to upgrade my cucumber/serenity project but sadly this breaks more then fixes one of the issues is when I want to run a seperate feature file I get the message from intellij
Error:Kotlin: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.13.
But as far as I know and see I never use kotlin. It's a maven project also with following pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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>be.nbb.cph</groupId>
<artifactId>hive-serenity</artifactId>
<version>1.0-SNAPSHOT</version>
<name>cph-serenity</name>
<description>Hive Selenium testing</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<serenity.version>2.6.0</serenity.version>
<serenity.maven.version>2.6.0</serenity.maven.version>
<serenity.cucumber.version>2.6.0</serenity.cucumber.version>
<encoding>UTF-8</encoding>
<tags></tags>
<webdriver.base.url></webdriver.base.url>
<!-- <maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<serenity.version>2.1.5</serenity.version>
<serenity.cucumber.version>1.9.50</serenity.cucumber.version>-->
<webdriver.driver>chrome</webdriver.driver>
<webdriver.remote.driver>chrome</webdriver.remote.driver>
<serenity.dry.run>false</serenity.dry.run>
<hive.env>local</hive.env>
<cucumber.runner>**/cucumber/CucumberTestSuite.java</cucumber.runner>
<serenity.browser.height>1024</serenity.browser.height>
<serenity.browser.width>1400</serenity.browser.width>
</properties>
<profiles>
<profile>
<id>dryrun</id>
<properties>
<serenity.dry.run>true</serenity.dry.run>
</properties>
</profile>
<profile>
<id>env:local</id>
<properties>
<hive.env>local</hive.env>
<injected.tags>env:local</injected.tags>
<cucumber.runner>**/cucumber/CucumberTestSuite.java</cucumber.runner>
<serenity.project.name>NBB Hive Automated Testing #uat
</serenity.project.name>
</properties>
</profile>
<profile>
<id>env:dev</id>
<properties>
<hive.env>dev</hive.env>
<injected.tags>env:dev</injected.tags>
<cucumber.runner>**/cucumber/CucumberTestSuite.java</cucumber.runner>
<serenity.project.name>NBB Hive Automated Testing #dev
</serenity.project.name>
</properties>
</profile>
<profile>
<id>env:uat</id>
<properties>
<hive.env>uat</hive.env>
<injected.tags>env:uat</injected.tags>
<cucumber.runner>**/cucumber/CucumberTestSuite.java</cucumber.runner>
<serenity.project.name>NBB Hive Automated Testing #uat
</serenity.project.name>
</properties>
</profile>
<profile>
<id>env:prd</id>
<properties>
<hive.env>prd</hive.env>
<injected.tags>env:prd</injected.tags>
<cucumber.runner>**/cucumber/CucumberTestSuite.java</cucumber.runner>
<serenity.project.name>NBB Hive Automated Testing #prd
</serenity.project.name>
</properties>
</profile>
<profile>
<id>target:desktop</id>
<properties>
</properties>
</profile>
<profile>
<id>target:mobile</id>
<properties>
<serenity.browser.height>1024</serenity.browser.height>
<serenity.browser.width>700</serenity.browser.width>
</properties>
</profile>
<profile>
<id>grid:nbb-dev</id>
<properties>
<webdriver.remote.url>http://swvnchseld01.nbb.local:4444/wd/hub</webdriver.remote.url>
</properties>
</profile>
<profile>
<id>grid:nbb-prd</id>
<properties>
<webdriver.remote.url>http://swvnchselp01.nbb.local:4444/wd/hub</webdriver.remote.url>
</properties>
</profile>
<profile>
<id>grid:local</id>
<properties>
<webdriver.remote.url>http://localhost:4444/wd/hub</webdriver.remote.url>
</properties>
</profile>
<profile>
<id>grid:none</id>
<properties>
</properties>
</profile>
<profile>
<id>browser:edge</id>
<properties>
<hive.browser>edge</hive.browser>
<injected.tags>browser:edge</injected.tags>
<webdriver.remote.driver>edge</webdriver.remote.driver>
</properties>
</profile>
<profile>
<id>browser:firefox</id>
<properties>
<hive.browser>firefox</hive.browser>
<injected.tags>browser:firefox</injected.tags>
<webdriver.driver>firefox</webdriver.driver>
<webdriver.remote.driver>firefox</webdriver.remote.driver>
</properties>
</profile>
<profile>
<id>browser:chrome</id>
<properties>
<hive.browser>chrome</hive.browser>
<injected.tags>browser:chrome</injected.tags>
<webdriver.driver>chrome</webdriver.driver>
<webdriver.remote.driver>chrome</webdriver.remote.driver>
</properties>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-core</artifactId>
<version>${serenity.version}</version>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-cucumber6</artifactId>
<version>${serenity.cucumber.version}</version>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-screenplay</artifactId>
<version>${serenity.version}</version>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-screenplay-webdriver</artifactId>
<version>${serenity.version}</version>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-ensure</artifactId>
<version>${serenity.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.13</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.6.2</version>
</dependency>
</dependencies>
<!-- plugins -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<systemPropertyVariables>
<password>${hive_test_account_1_password}</password>
<password>${hive_test_account_2_password}</password>
<password>${hive_test_account_3_password}</password>
<password>${hive_test_account_4_password}</password>
<password>${hive_test_account_5_password}</password>
<password>${hive_test_account_6_password}</password>
</systemPropertyVariables>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<includes>
<include>**/*Test.java</include>
<include>**/Test*.java</include>
<include>**/*TestSuite.java</include>
<include>**/When*.java</include>
</includes>
<systemPropertyVariables>
<webdriver.base.url>${webdriver.base.url}</webdriver.base.url>
</systemPropertyVariables>
<!-- <parallel>classes</parallel>
<parallel>methods</parallel>
<useUnlimitedThreads>true</useUnlimitedThreads>-->
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.serenity-bdd.maven.plugins</groupId>
<artifactId>serenity-maven-plugin</artifactId>
<version>${serenity.version}</version>
<executions>
<execution>
<id>serenity-reports</id>
<phase>post-integration-test</phase>
<goals>
<goal>aggregate</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/${hive.env}/${hive.browser}/${current.time}
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>current-time</id>
<phase>validate</phase>
<goals>
<goal>timestamp-property</goal>
</goals>
<configuration>
<name>current.time</name>
<pattern>yyyyMMdd_HHmmss</pattern>
<timeZone>CET</timeZone>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Does anybody know what's going wrong or how to fix this?

aar file not added into war axis2-aar-maven-plugin

I am trying to careate a sample webservice with Axis2 and Maven, while the aar file is generating but in aar, as war file get generated first and aar file afterwordds. can someone provide some help here.
<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.prash</groupId>
<artifactId>test.webservice</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>test.webservice Maven Webapp</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>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2.1-b03</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2</artifactId>
<version>1.6.2</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-aar-maven-plugin</artifactId>
<version>1.6.2</version>
<type>maven-plugin</type>
</dependency>
<dependency>
<groupId>axis2</groupId>
<artifactId>axis2-xmlbeans</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-adb</artifactId>
<version>1.6.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-aar-maven-plugin</artifactId>
<version>1.6.2</version>
<extensions>true</extensions>
<configuration>
<!-- Set true if you want Depending Jar to be included into AAR file-->
<includeDependencies>false</includeDependencies>
<aarName>StockQuoteService</aarName>
<outputDirectory>${basedir}/src/webapp/</outputDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>aar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<finalName>test.webservice</finalName>
</build>
Issue resolved. I have done following changes into pom.xml
<plugins>
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-aar-maven-plugin</artifactId>
<version>1.6.2</version>
<extensions>true</extensions>
<configuration>
<!-- Set true if you want Depending Jar to be included into AAR file-->
<includeDependencies>false</includeDependencies>
<aarName>StockQuoteService</aarName>
<outputDirectory>${basedir}/target/test.webservice/WEB-INF/services</outputDirectory>
</configuration>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>aar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>

Run tests from maven zip assembly

I have finally succeeded in getting Maven to zip together a bunch of jars using an assembly file and install it to my local repository. That was difficult enough...
Now my goal is to configure another maven project so that when I do "mvn test", it will pull in that zip, unpack it, and run tests from the jars within that zip file. Does anyone know how to do this?
Here is the POM for the assembly project:
<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.pason</groupId>
<artifactId>RigFocusOnDataHub</artifactId>
<name>RigFocusOnDataHub</name>
<version>12.2.0-SNAPSHOT</version>
<packaging>pom</packaging>
<dependencies>
...
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<configuration>
<descriptors>
<descriptor>RigFocusOnDH.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>zip</id>
<!-- this is used for inheritance merges -->
<phase>package</phase>
<!-- append to the packaging phase. -->
<goals>
<goal>single</goal>
<!-- goals == mojos -->
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Here is the POM for the second project. Unfortunately, instead of downloading the zip file for RigFocusOnDataHub, it just fetches the jars for all of RigFocusOnDataHub's dependencies from the local repo.
<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.pason</groupId>
<artifactId>RigFocusDHSystemTest</artifactId>
<version>12.2.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.pason</groupId>
<artifactId>MurphyRigFocus</artifactId>
<version>2.0.0-SNAPSHOT</version>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>com.pason</groupId>
<artifactId>RigFocusOnDataHub</artifactId>
<version>12.2.0-SNAPSHOT</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>process-test-classes</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.pason</groupId>
<artifactId>MurphyRigFocus</artifactId>
<version>2.0.0-SNAPSHOT</version>
<type>test-jar</type>
<outputDirectory>${project.build.directory}/tests/MurphyRigFocus</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>com.pason</groupId>
<artifactId>RigFocusOnDataHub</artifactId>
<version>12.2.0-SNAPSHOT</version>
<type>zip</type>
<outputDirectory>${project.build.directory}/tests/MurphyRigFocus</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.6</version>
<configuration>
<testClassesDirectory>${project.build.directory}/tests/MurphyRigFocus</testClassesDirectory>
<reportsDirectory>${project.build.directory}/surefire-reports/MurphyRigFocus</reportsDirectory>
<includes>
<include>**/*IT.*</include>
</includes>
<argLine>-Djava.library.path=${basedir}/target/classes/</argLine>
<forkMode>pertest</forkMode>
</configuration>
</plugin>
</plugins>
</build>
You would need to:
extract the jars from the zip - this is easy enough with maven-dependency-plugin
cut transitive dependencies so your jars don't end up in the path twice - you can do that at the source with maven-shade-plugin or in the test project itself with dependencies exclusions
add the jars to your test classpath, there are many ways to do that, I would try to use additional parameters in surefire configuration first

Unzip dependency in maven

I have the following dependency in maven
<dependency>
<groupId>org.hyperic</groupId>
<artifactId>sigar-dist</artifactId>
<version>1.6.5.132</version>
<type>zip</type>
</dependency>
This creates sigar-dist-1.6.5.132.zip in my repository.
I have seen this question here, however I still can't make it work.
How can I unzip the sigar-dist.zip and place the content in a directory in my project? What is the mvn call I have to do to make it work?
You can do it with dependencies:unpack-dependencies:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>unpack-sigar</id>
<phase>package<!-- or any other valid maven phase --></phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeGroupIds>org.hyperic</includeGroupIds>
<includeArtifactIds>sigar-dist</includeArtifactIds>
<outputDirectory>
${project.build.directory}/wherever/you/want/it
<!-- or: ${project.basedir}/wherever/you/want/it -->
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Reference:
Unpacking project dependencies
dependency:unpack-dependencies
just a follow up on answer from #Sean Patrick Floyd
this is my final pom.xml to download and unpack tomcat
<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.koushik.javabrains</groupId>
<artifactId>tomcat</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>tomcat</name>
<properties>
<tomcat.version>8.0.27</tomcat.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>unpack-tomcat</id>
<phase>package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeGroupIds>org.apache.tomcat</includeGroupIds>
<includeArtifactIds>tomcat</includeArtifactIds>
<outputDirectory>
${project.build.directory}
<!-- or: ${project.basedir}/wherever/you/want/it -->
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat</artifactId>
<version>${tomcat.version}</version>
<type>zip</type>
</dependency>
</dependencies>
</project>

How to include automatically xmlbeans generated code into maven jar?

I have a project which uses Apache Xmlbeans for databinding. Currently it is very simple it only has some Schema-Files in src/main/xsd and xsdconfig in src/main/xsdconfig.
I want to include the generated Classes into the generated jar-File. It works if I specify the xmlbeans goal:
"mvn xmlbeans:xmlbeans package" --> Creates a Jar with the xmlbeans classes
But I want to do this within the normal build cycle: "mvn package" --> should create a jar with the xmlbeans classes, but won't.
The pom 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>org.test</groupId>
<artifactId>xmlbeans-maven-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>maven-xmlbeans-plugin</artifactId>
<version>2.3.3</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.4.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
I tried to bind it manually to the "generate-sources" (And to the "compile" phase, too) phase, but it does not work.
<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>de.leradon</groupId>
<artifactId>xmlbeans-maven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>maven-xmlbeans-plugin</artifactId>
<version>2.3.3</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>xmlbeans</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.4.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
How can I configure the plugin, so that when I run "mvn package" all the generated classes are packaged into the jar?
Greetings,
lerad
If you configure the plugin under pluginManagement, you still need to declare it under plugins. To simplify, I'm not using the pluginManagement in the pom.xml below:
<project>
...
<dependencies>
...
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.4.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xmlbeans-maven-plugin</artifactId>
<version>2.3.3</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>xmlbeans</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
With this POM (and some XSD in src/main/xsd which is the default location), running mvn clean package just works (i.e. sources are generated from the XSD, compiled and packaged as part of the build).
Try this.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xmlbeans-maven-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<id />
<phase>generate-sources</phase>
<goals>
<goal>xmlbeans</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory>src/main/xsd</schemaDirectory>
<staleFile>${project.build.directory}/generated-sources/xmlbeans/.staleFlag</staleFile>
<verbose>false</verbose>
<quiet>false</quiet>
<javaSource>1.6</javaSource>
</configuration>
</plugin>