Multiple XSD schemas for castor with castor-maven-plugin - maven

Is it possible to work with multiple xsd schemas with castor-maven-plugin simultaneously?
I use it in rotation (schema1 and schema2) in POM and it works:
<build>
...
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>castor-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<schema>src/main/castor/schema1.xsd</schema>
<dest>src/main/java</dest>
<packaging>com.path.to.schema1.beans</packaging>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
...
with a little problem: mvn:install collects all classes to target except chema2.crd (or schema1 if I use schema2). I have to copy file manually.
Can I fix it? Are there any ways to configure castor-maven-plugin ?

Try using multiple executions like this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>castor-maven-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<id>firstSchema</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schema>src/main/castor/schema1.xsd</schema>
<dest>src/main/java</dest>
<packaging>com.path.to.schema1.beans</packaging>
</configuration>
</execution>
<execution>
<id>secondSchema</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schema>src/main/castor/schema2.xsd</schema>
<dest>src/main/java</dest>
<packaging>com.path.to.schema2.beans</packaging>
</configuration>
</execution>
</executions>
</plugin>

Related

Maven merging changes plugin execution order in same Phase

I'm working on a Project which uses the same Plugin Multiple Times in multiple Parent Pom Files.
Normally, if you use two Plugins in the same maven phase, it will execute the plugin which is first defined in the POM.
In my case Maven merges the Plugins which causes my Plugins to be executed in the wrong order.
I want my Plugins to be executed in the following Order:
first,second,third,fourth
But the order it executes them is:
first,second,fourth,third
These are my POM's:
ParentParentPom.xml
<plugins>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<configuration></configuration>
<executions>
<execution>
<id>first-plugin-execution</id>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>second-plugin-execution</id>
<phase>generate-sources</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
ParentPom.xml
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>third-plugin-execution</id>
<phase>compile</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<configuration></configuration>
<executions>
<execution>
<id>fourth-plugin-execution</id>
<phase>compile</phase>
<goals>
<goal>replace
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
Effective Pom.xml
I looked into the Effective Pom of my Project and saw that Maven merged the plugins like this:
<plugins>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<id>first-plugin-execution</id>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
<execution>
<id>fourth-plugin-execution</id>
<phase>compile</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>second-plugin-execution</id>
<phase>generate-sources</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
<execution>
<id>third-plugin-execution</id>
<phase>compile</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
Changing the Phases of the Plugins is not an option because these plugins rely on plugins which are executed in the compile phase and other plugins rely on the execution of the thrith and fourth execution too.
Is there any way I can prevent maven from merging these plugins together, so that they stay in the right order?

Goal copy-dependencies in maven-dependency-plugin is not executed

I have the following plugin configuration :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
</configuration>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
</plugin>
When calling mvn dependency:copy-dependencies dependencies are indeed copied, and at the correct location (alternateLocation). But when I'm calling mvn package nothing is performed. What am I missing ?
As per documentation, you need to have your configuration inside the execution.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<!-- configure the plugin here -->
</configuration>
</execution>
</executions>
</plugin>
We only see parts of your POM, but I guess you put the plugin into <pluginManagement> and not into <plugins> where it belongs.

Spring Boot jar - META-INF inside BOOT-INF folder

Is there any way to have META-INF folder inside BOOT-INF in spring boot packaging jar?
This might be a trivial question, but not sure how to do it. Below is the way i am packaging right now which created three folders BOOT_INF, META_INF, ORG. The reason of asking this is because runnable jar is not able to locate a folder which is inside META-INF.
<build>
<finalName>XYZ</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>XYZ</version>
<executions>
<execution>
<id>default-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<excludes>
<exclude>XYZ</exclude>
<exclude>XYZ</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>XYZ</mainClass>
<addResources>true</addResources>
<wait>1000</wait>
<maxAttempts>250</maxAttempts>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>XYZ</version>
<configuration>
<tarLongFileMode>XYZ</tarLongFileMode>
<tarLongFileMode>XYZ</tarLongFileMode>
<descriptors>
<descriptor>XYZ</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>XYZ</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Any help which plugin i can use in order to do that?
Similar issue resolved in my case after adding META-INF folder under resources.

maven command to execute multiple executions in plugin

I am trying to generate sources from wsdl
This is my plug-in.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/target/generated-sources/wsdl</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>1.12</version>
<executions>
<execution>
<id>gen1</id>
<phase>generate-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<packageName>pkg1</packageName>
<wsdlDirectory>${basedir}/src/main/resources/wsdl/xml1</wsdlDirectory>
<keep>true</keep>
<sourceDestDir>${basedir}/target/generated-sources/wsdl</sourceDestDir>
</configuration>
</execution>
<execution>
<id>gen2</id>
<phase>generate-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<packageName>pkg2</packageName>
<wsdlDirectory>${basedir}/src/main/resources/wsdl/xml2</wsdlDirectory>
<keep>true</keep>
<sourceDestDir>${basedir}/target/generated-sources/wsdl</sourceDestDir>
</configuration>
</execution>
</executions>
</plugin>
When I run mvn compile, only gen1 is generated. I want it to generate both executions. I cannot combine them as they are residing in different wsdl directories and require different packagenames.
I understand that I can split into profiles and run it like mvn compile -Pprofile1,profile2.
But is there an easier way?

How can I combine jars using Maven?

The following snippet creates 2 JARS:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>build-dependency</id>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>dependency</classifier>
<classesDirectory>${project.build.directory}\dependency</classesDirectory>
<includes>
<include>${dependancyInclude}</include>
</includes>
</configuration>
</execution>
<execution>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>module</classifier>
<classesDirectory>${project.build.directory}\classes</classesDirectory>
</configuration>
</execution>
</executions>
</plugin>
I would like to combine these two JARs into one using the assembly plugin, currently I have the following:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2</version>
<executions>
<!-- Combine all the JARs in the /target folder into one JAR -->
<execution>
<id>make-assembly</id>
<phase>compile</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<attach>true</attach>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>${project.artifactId}-${project.version}</finalName>
<appendAssemblyId>true</appendAssemblyId>
</configuration>
</execution>
</executions>
</plugin>
Currently only one of the two JARS in included in the final JAR that is created by the assembly plugin.
If I understand you correctly, you actually want to merge the jar files into one big jar file. This can be achieved using the maven-shade-plugin (instead of the maven-assembly-plugin).
For example:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.0</version>
<configuration>
<!-- Put your configuration here, if you need any extra settings.
(You should be okay with the defaults). -->
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>

Resources