Maven : wrong local POM and versioning issue - maven-2

I have 4 Modules (4 POM XML files ) and one parent XML file
I have this directory structure , please refer to the screen shot
http://postimage.org/image/1gjk3mdg/
Currently this error is occuring when i ran the Parent POM.xml file (which internally runs all the Module's POM xml files)
The project com.bayer:tata-mw:1.0 (C:\tata\middleware\pom.xml) has 1 error
[ERROR] Non-resolvable parent POM: Could not find artifact com.bayer:tata:pom:1.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM # line 9, column 12 -> [Help 2]
To resolve the Parent POM error i am refering like this on to my child POM.xml file
<parent>
<groupId>com.bayer</groupId>
<artifactId>tata</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>c:/tata/pom.xml</relativePath>
</parent>
Please guide me whether this is correct approach or not , becuase when i did that the error still persists .
Thank you .

In parent section, relativePath xml tag should point to a path in ... relative !
Like :
<parent>
<groupId>com.bayer</groupId>
<artifactId>tata</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Update maven with force update of Snapshot/Release
right click on project-->maven-->update project-->check force update of snapshot

follow below steps -
1- Create a Parent Maven project
Go to your .m2 folder( C:\Users.m2 ) and delete all repository.
2- Go your Maven project
Update your Maven Project

Simply add an empty <relativePath/> to so that it can resolve the parent pom -
<parent>
<groupId>com.proj</groupId>
<artifactId>com.proj.api</artifactId>
<version>0.1.1</version>
<relativePath></relativePath>
</parent>
Another preffered way to create modular maven projects is to follow below steps -
1- Create a Parent Maven project
new-->project-->Maven Project-->Check Create a simple project
checkbox-->provide all Maven Ids
2- Create Maven Module and add the module to previously created parent project
new-->other..-->Maven Module-->Check Create simple project
checkbox-->name your module -->Browse Parent projst-->select
previously created project

Related

Why does Intellij IDEA say that used properties are unused?

I have a properties file in my Java maven project. I have one class which loads these properties and stores them as constants.
//Constants.java file has this code.
Properties properties = new Properties(blah...);
String username = properties.getProperty("my.username");
System.out.println(username);
Despite using my.username property and the username variable, Intellij IDEA says that it is unused. Why ? I tried to invalidate caches and restart the IDE, but it did not change anything.
As a result, its hard to find out which properties are actually unused and remove them.
Here is the project structure :
PROJECT1
-> PROJECT2
--> src > main > resources > folder > my.properties
--> pom.xml
-> PROJECT3
--> src > main > java > packagea.b.c > packaged > packagee > Constants.java
--> pom.xml
pom.xml
The issue is not reproducible:
If you have the Minimal, Complete, and Verifiable example, please share it so that we can investigate why the it happens in your specific project.
Here is the properly working sample: unused-properties.zip.
To match your multi module Maven project from the description I've created another sample project to illustrate the configuration and the properly working inspection.
Get the sample project here: unused-multimodule-maven.zip.
This project has an aggregate pom.xml in the root directory and 2 modules: app and properties where app depends on properties.
Proof of working screenshot:
Notice that the app module depends on the properties module. This dependency is achieved via the following pom.xml configuration of the app module.
<dependencies>
<dependency>
<groupId>com.jetbrains.support</groupId>
<artifactId>properties</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>

How to deploy pom.xml as SNAPSHOT with maven?

I have a pom.xml and i want to use it as the parent pom.xml of my project.
and want to make the name for the pom.xml which was uploaded on Nexus like ABC-root-pom-2.0.0-SNAPSHOT.pom
so could anyone tell me what the command is using maven ?
Thanks
Do not worry about what name the pom will have on the repository manager. The Maven repository format dictates that.
To get a Maven project with pom packaging deployed you have to do the normal steps of adding the distributionManagment to the pom and the credentials to the settings.xml. Then you run
mvn clean deploy
and thats it. Your other project can then reference it. An example for such a pom project is my progressive-organization-pom.

maven release:perform and parent pom

I have a library which I "mavenized" recently and put into a local git repository.
In order to lock some plugin versions I created a simple parent pom which defines the plugin versions via pluginManagement (the parent pom file is not checked into any SCM repository). I specify the parent pom in my libraries pom file:
<parent>
<groupId>org.my.company</groupId>
<artifactId>superpom</artifactId>
<version>1</version>
</parent>
I use default directory structure.
When I try to perform a release using the release plugin I run into a problem.
mvn release:prepare runs fine however when I run mvn release:perform maven checks out the corresponding tag from my local git repository into the target/checkout folder and tries to run the deploy goal.
However the build fails with the error message that it can't find the parent pom file defined in my library pom file.
I assume that's related to the fact that maven tries to find the parent pom file in the target folder and it is not available there.
Is there an easy way how to solve this problem?
Update:
I have multiple unrelated GWT libraries which should share the common company parent pom file in order to specify plugin versions.
The parent pom is just used for defining some default versions and won't contain any module definitions because all GWT libraries are unrelated.
The GWT library are really simple and have no real dependencies to any other libraries apart from the default ones (gwt, junit)
Update2:
I solved the problem by installing the superpom into my local repository by running mvn install in the folder of my superpom.
The first fail you did is not to versionise the parent pom where you defined the pluginManagement area. This is the first step you must do put the pom.xml which you like to use a parent. Secondly you have to put the information about the VCS into the scm area of that pom. After you cleaned up everything you must do a mvn release:prepare release:perform of the parent pom. After that you are able to use it as a parent in your other projects. Furthermore you should define the distributionManagement area in your parent pom.

Maven - Best way to refer to a directory on the system path

I am trying to build an RPM from my Maven project. I have 5 different modules and each one has its own pom.xml, In the root I have one pom.xml which builds all modules (Typical Maven Setup). When I build an RPM, I want to include a directory that is not part of the maven directories. Its above a directory [from the root folder that contains my maven modules]. What is the best way to include that in my RPM? or rather what is the best way to refer to a directory with out hardcoding the path? I am confused about ${baseDir} and what it refers to?
Thank you.
${project.basedir} refers to the root of the project, ie where the pom.xml is, so you could use that in <systemPath>${project.baseDir}/../../dirYouWant</systemPath>
In general though, Maven best-practices would frown about relying on the relative paths around your projects from being there. Instead, I suggest deploying those files as there own project to your maven repository (as a zip, jar, whatever), and then getting them as part of your rpm build. Depending on what plugin you are using to build your RPM, you can unpack those files automatically.
Try this
<dependency>
...groupid,artifactid etc..
<scope>system</scope>
<systemPath>path/to/your/jar</systemPath>
</dependency>
Did you mean you want to add another project to your maven build being level above?
you can do it like this :
in your parent pom :
<modules>
<module>../projectdirectory</module>
</modules>
in your projectdirectory pom :
<parent>
<groupId>...</groupId>
<artifactId>...parent...</artifactId>
<version>...</version>
<relativePath>../parentProject/pom.xml</relativePath>
</parent>

Maven structor - how shall i make this the right way?

I am sitting with a problem on how to structor a maven project.
This is the structur on the project
So I am able to build every project like bbbbb/pom.xml and so on. Fx the bbbb/pom.xml has a parent that is in aaaaaa/parent/pom.xml. Then this has a parent in the root. But if I now want to build them all and add them all to a package how is that done?
Usual structure for nested maven projects would be:
/parent
pom.xml
/sub1
pom.xml
/sub2
pom.xml
...
Each pom in subX prohect references parent and parent pom lists SubX as modules. This way you should be able to build each subX project individually as well as everything from parent.
Not clear what you mean by 'add them all to a package'? Generally in maven there is 'one artifact per project' - so if you need say EAR you would create another subproject under same parent with packaging=ear. If you need 'all in one jar' you could look at maven-assembly-plugin, again in separate subproject perhaps.