Maven Multimodul project in Eclipse and in SVN - java

I have an existing project, MainProject. I want to convert it to a multimodule project. In Eclipse I created a parent modul, which is just a pom modul and another modul, Modul_1.
Then I moved my MainProject in parent file directory. (Actually i did not want to move in parent folder. unfortunately to make it possible that Main_project finds the parent modul, i must do that)
Works fine..
It looks like:
-->ParentModule
------>Mainproject
------>Modul_1
Modul_1 is only needed in jenkins. It means the programmers should only care about MainProject.
How should I check in the project in SVN? With the same file structure or can i check in independently in SVN?

if the mainproject doesn't refer to ParentModule, you could layout it like this :
-->ParentModule
-->MainProject
-->Modul_1
in parentmodule's pom.xml :
<modules>
<module>../MainProject</module>
<module>../Modul_1</module>
</modules>
for jekins, there are 2 ways to configure job :
checkout parent folder and point pom's location to ParentModule/pom.xml
checkout 3 svn locations to each folder for 3 projects and point pom to ParentModule/pom.xml
for eclipse , you can checkout only MainProject.

Related

Maven - from where is "Release-Name" field data retrieved while creating MANIFEST.MF

We are using Jenkins maven plugin for building and deploying war applications. In the jenkinsfile we have the command (I removed the list of profiles for the sake of simplicity):
mvn release:clean release:prepare -P<profiles> -U -DautoVersionSubmodules="true" -Darguments="-T 1C -DskipTests=true" -V --batch-mode --errors
The built war artifact has MANIFEST.MF file with field Release-Name set to main.
Release-Name: main
In the parent pom.xml there are some extra settings for customize MANIFEST.MF but it seems to me that "Release-Name" is added by default because it is not listed below:
<manifestEntries>
<Version>${project.version}</Version>
<Revision-Number>${buildNumber}</Revision-Number>
<Branch>${GIT_BRANCH}</Branch>
<Local-Branch>${scmBranch}</Local-Branch>
</manifestEntries>
So I tried to look into the maven release plugin source code from this repository but I couldn't find anything helpful.
Then the main question is how the field "Release-Name" is filled because I'd like to change it into some more meaningful value.
The problem, as it turned out, was in another module of the project, which was downloaded from remote repository, while building the entire artifact. In this extra module, there was a definition in pom used to set the value of Release-Name in the manifestEntries section.
<Release-Name>${releaseName}</Release-Name>

build plugin in multi-module maven project

I have a multi-module maven project that I am attempting to build.
The project structure is, generally:
Parent project (pom)
Sub Module 1
Sub Module 1A
Sub Module 1B
Sub Module 2
Sub Module 3
Inside of the parent project POM, I have the net.revel.code.formatter plugin defined in my build section to format the JAVA code inside of all of the sub-projects.
One of the attributes that I have to define in the plugin is the location of the configuration file. The file is located in a resource directory inside of Sub Module 3
I have the location attribute specified as ${project.parent.basedir}/submodule3/src/main/resources/eclipse/formatter.xml
The problem that I am running into is that when Sub Module 1A (as an example) is building, it seems that the ${project.parent.basedir} is resolving to the parent directory for Sub Module 1A (which is Sub Module 1) instead of the root of the project (where the property is actually defined).
Could someone help me sort out how to resolve this?

Maven Site Plugin: Define url in parent without adding subdirectories

I define a URL for a Maven site by
<distributionManagement>
<site>
<id>site-nexus</id>
<url>dav:http://ik-repo1:8084/nexus/content/sites/site/${project.groupId}/${project.artifactId}/${project.version} </url>
</site>
</distributionManagement>
If I add this to my pom, the site gets deployed as expected: It can be accessed through the URL that was specified.
But, if I add this to a parent POM, subdirectories are added to this url. I guess this happens along the lines of
"If subprojects inherit the (distribution) site URL from a parent POM, they will automatically append their artifactId to form their effective deployment location. This goes for both the project url and the url defined in the element of the pom."
in https://maven.apache.org/plugins/maven-site-plugin/examples/multimodule.html .
My parent POMs are not part of a multi-module build, but are just used to share configuration for all of our projects (some hundred projects, actually). So I would like to specify a URL in the parent POM that should be used for each project as if it was specified in the POM itself (i.e. without subdirectories in the URL beyond the ${project.version} directory that I defined myself).
How can I achieve that?
It's marked as an improvement for Maven, see https://issues.apache.org/jira/browse/MNG-5951 for all the details.

Maven multi module jenkins project

I've a multi-module maven application that we need build through Jenkins.
Project structure is like:
a.xml
<artifactId>parent-1</artifactId>
<modules>
<module>lookup-1</module>
<module>lookup-2</module>
</modules>
lookup-1.xml
<artifactId>lookup-1</artifactId>
<parent>
<groupId>com.lookup</groupId>
<artifactId>parent-1</artifactId>
<version>1.0.1-SNAPSHOT</version>
</parent>
<name>lookup-1</name>
lookup-2.xml
<artifactId>lookup-2</artifactId>
<parent>
<groupId>com.lookup</groupId>
<artifactId>parent-1</artifactId>
<version>1.0.1-SNAPSHOT</version>
</parent>
<name>lookup-2</name>
now,
mvn clean install -f a.xml works fine. For this I created one Jenkins job.
Now, same as a.xml, I've another project with b.xml. b.xml has the same code as of a.xml except different Ids. So, I've created another jenkins job for b.xml.
Both jobs work fine. But, now I want to build both these project from single Jenkins job based on which project we commit in Git. For, this I want to have a new project(pom.xml) and where I want to put both a and b under modules tag. Like this:
pom.xml
<name>combined_project</name>
<artifactId>combined_project</artifactId>
<modules>
<module>a</module>
<module>b</module>
</modules>
a.xml
<artifactId>parent-1</artifactId>
<name>a</name>
<parent>
<artifactId>combined_project</artifactId>
</parent>
<modules>
<module>lookup-1</module>
<module>lookup-2</module>
</modules>
But, its not working for me. I'm getting following exception in maven:
Child module D:\....\a of D:\....\pom.xml does not exist
Maven not able to find child module.
I've following project structure:
project
|_ lookup-1
|_ lookup-1.xml
|_ lookup-2
|_ lookup-2.xml
|_ a.xml
|_ b.xml
|_ pom.xml
Any hint?
a.xml has 2 sub modules lookup-1 and lookup-2. By default maven is looking for the sub modules in the nested maps. So you need to have the following directory structure:
<parent>
|
+- a/pom.xml
| |
| +- lookup-1/pom.xml
| |
| +- lookup-2/pom.xml
|
+- b/pom.xml
|
+- pom.xml
Alternative is to change the parent into
<name>combined_project</name>
<artifactId>combined_project</artifactId>
<modules>
<module>a</module>
<module>b</module>
<module>lookup-1</module>
<module>lookup-2</module>
</modules>
Maven follows a project structure and each <module> will contain a pom.xml file. As you have explicitly stated the pom file in command line that file will be selected as the pom.xml for that project. However, for every submodule that is listed maven will search for the exact file named "pom.xml" for each submodule.
From the folder structure provided, it can be inferred that a.xml can act as a pom file when explicitly specified in command-line but it cannot act as a module as it does not have a dedicated folder with pom.xml.
A maven project in general has the following structure:
archetype-id(folder)
pom.xml(packaging: pom)(with one module module-artifact-id)
module-artifact-id(folder)
pom.xml
If you are attempting to build only the module that has been updated then the module that is not checked in recently will not be part of the newly created archive. But if you still would want to do it for some "special" reason. The following method might be the one you are looking for:
(I wouldn't recommend it -- as it is messy and goes against conventions)
Have two sub-modules in a single project and also Have two .xml files (pom files to be specified in commandline). In one xml file lets say "a.xml" "module-1" is to be specified as a module and in "b.xml" "module-2" is to be specified as a module.
Using the currently modified module invoke the build on that pom file. Example, if module-1 is modified specify a.xml in the command line as the pom.xml.
Please note that I have not attempted it but if it is possible this is one of the ways I can think of by which we can accomplish what you are looking for.
Reference for passing parameters : Pass a dynamic parameter in Jenkins build
Two possibilities :
Either you need to fix the path of your submodules in the modules section of the parent pom.
While creating a jenkins job you will have to tell jenkins to clone submodules as well. when I started with jenkins, I faced similar problem. The solution was to enable "Recursively update submodules" checkbox under Advanced scm behaviors in Jenkins UI.

Maven , How to add dependency of local system java-source?

I want to build one jar that includes a child module which depends on other package of my own project.
The output one jar should include all the related class (both from jar and my own project's classes).So the child module's classes is the base classes that should be included in the output jar,and these import some classes of my own project.All the related classes in my own project should be included.
for more detail please visit How to automatically collect all related class into one jar (use maven)?
Here is what I already find:
<project>
<dependencies>
<dependency>
<scope>system</scope>
<systemPath>D:\how\to\write</systemPath>
<groupId>how.to.write</groupId>
<artifactId>how-to-write</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>java-source</type>
</dependency>
</dependencies>
</project>
The error message is : Could not find artifact how.to.write:how-to-write:jar:sources:0.0.1-SNAPSHOT at specified path D:\how\to\write
the path D:\how\to\write contains my own project's classes that could support the build
Your maven dependency will look for a jar file with name how.to.write:how-to-write:jar:sources:0.0.1-SNAPSHOT in D:\how\to\write directory. Since you do not have one, the build will fail.
If your own project does not use maven, then you should create a jar file and place it in D:\how\to\write location and rename it to how.to.write:how-to-write:jar:sources:0.0.1-SNAPSHOT. Then your build mvn clean install will be success.
The command for creating jar file is jar cf jar-file input-file(s).
Have a look at this page on how to create a jar file

Categories

Resources