Reputation: 1078
I have multiple Java projects (packaged to jars) in my product which have a single pom
combining them as modules. Each of the projects has different dependencies and their combined dependencies are defined in the parent pom
. I want to prepare the output for production and do the following:
Anyone knows of a way to do it without having to manually copy each of the above for all the projects? I also want my future projects to support this deployment procedure without having to work too hard and specific.
Upvotes: 2
Views: 593
Reputation: 1078
I will summarize What I did in the assembly XML (to answer all of my issues) in addition to Andrey Borisov answer.
copy the configuration files (found under the src/main/resources) from all the projects to a third folder. [Used the "fileset" element]
http://maven.apache.org/xsd/assembly-1.1.2.xsd"> bin dir false
<moduleSets>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<binaries>
<outputDirectory>modules</outputDirectory>
<unpack>false</unpack>
</binaries>
</moduleSet>
</moduleSets>
<dependencySets>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>lib</outputDirectory>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>my DIR 1</directory>
<excludes>
<exclude>*log4j*</exclude>
</excludes>
<outputDirectory>resources</outputDirectory>
</fileSet>
<fileSet>
<directory>my DIR 2</directory>
<outputDirectory>resources</outputDirectory>
</fileSet>
</fileSets>
Upvotes: 0
Reputation: 2448
I have the same requirements in my project.
There is a difference between using the Jenkins with ClearCase and SVN. If you were using SVN you should have checked out your projects into your main project, and worked on them like there were on the same dir.
After checking out my child projects I can work on them, in the example you can see a portion from the assembly.xml, in which core and scheduler are the child projects.
</fileSet>
<fileSet>
<directory>./core/src/main/resources/</directory>
<outputDirectory>./examples</outputDirectory>
<includes>
<include>*</include>
</includes>
</fileSet>
<fileSet>
<directory>./scheduler/src/main/resources/</directory>
<outputDirectory>./examples</outputDirectory>
<includes>
<include>*</include>
</includes>
</fileSet>
This will basically copy the resources folder content into the main project example project.
You can do the same here, if all you projects are on the same vob, and available, you should specify a relative location to which you are going to copy all your resources. For example:
</fileSet>
<fileSet>
<directory>../../../your_sub_project1/src/main/resources/</directory>
<outputDirectory>./examples</outputDirectory>
<includes>
<include>*</include>
</includes>
</fileSet>
<fileSet>
<directory>../../../your_sub_project2/src/main/resources/</directory>
<outputDirectory>./examples</outputDirectory>
<includes>
<include>*</include>
</includes>
</fileSet>
This way, when running the primary pom, you will be able to access the content of the sub projects and copy the resources to a certain folder. Hope it helps..
Upvotes: 0
Reputation: 3170
You need to use Maven assembly plugin for this - here is example of zipping distributive (on production you need then just to unzip):
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>${project.basedir}/src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
and assembly XML
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>${env}</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<includes>
<include>com.mycompany:ear-project</include>
<include>com.mycompany:jnlp-project</include>
</includes>
<outputDirectory>libs</outputDirectory>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>src/main/resources</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
<fileSet>
<directory>target/docbook/pdf</directory>
<includes>
<include>index.pdf</include>
</includes>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
Please NOTE that for your 2 projects (EAR, JNLP) you can place dependencies via outputDirectory configuration.
Upvotes: 2