How do I get my parent pom to output tar.gz files - maven

I have a parent pom and children pon and when I run the mvn clean package on the parent pom I am getting .jar file, is there anyway to change this to tar.gz file? For the children files I have created assembly.xml files to specify tar.gz file do I need to do the same for parent pom?

Specify POM packaging:
<packaging>pom</packaging>
I'm a little surprised that your parent POM is working without that setting. I've received errors from Maven before when I create a new parent POM and forget to change the packaging from jar (default) to POM.

The parent is not really meant to produce artifacts other tan the pom.
You could try attaching the assembly plugin to a phase such as process-resources or something and try to have it package whatever resources you have in mind, but... generally, it's not a good idea to keep resources in your parent.
If the projects that extend this parent do not define <packaging/>, their packaging will default to pom.

Related

Using Maven scm:checkin to commit changes to module projects

I have a multi-module POM file:
...
<modules>
<module>../project1</module>
<module>../project2</module>
<module>../project3</module>
...
</modules>
...
Each of the modules is itself a Maven project with its own POM. Inside each of these POMs I have the scm tag defined with the developerConnection specified like this:
<scm>
<developerConnection>scm:svn:svn://hostname:port/path/to/trunk</developerConnection>
</scm>
My goal is to run the following Maven goals/options:
versions:update-parent versions:commit scm:checkin \
-Dmessage="automated commit" -Dusername=user -Dpassword=pass
My expected results are:
The parent of each module's POM is updated to the latest released version.
The changes to each POM would be checked in to the SVN path specified in the POM for the module. E.g. project1 POM checked in using project1 <scm>/<developerConnection> path, project2 checked in using project2 path, etc.
Actual Results:
The parent of each module's POM is updated to latest released version. This works as expected.
Only the multi-module POM is checked in to SVN, none of the module POMs are checked in. This is the problem.
Is there a way to achieve the expected results above or is this something that the SCM plugin simply was not designed to do? If it is possible, how would I modify what I have in order to get the results I want?
Note: I can't change the project structure - I can't put the modules inside of the parent project, they have to remain separate.
Not sure if it's relevant but I'm using Maven 3.3.9.

Which Pom is parent?

In a maven project which pom.xml is the parent pom? And is that the one I need to change in order to add a profile?
I have a simple project and am trying to add a profile to download from a specific repository but nothing's seems to be working.
I assume you have a multi-module build.
Parent relationship is optional between poms, and specified with the <parent> tag inside the pom.
You may point to a single pom, but if not, you point to a default super-pom.
Use mvn help:effective-pom to shed some light on your settings.
If you have a shared pom file, you can add profiles to that one, otherwise you need to include them in each pom.
Use mvn help:active-profiles to see which ones are enabled.
For ref: http://maven.apache.org/guides/introduction/introduction-to-profiles.html

Version in jar name

When I import mvn project into Intellij the jar file it generates doesn't include version. But mvn generated jar has name-version.jar format. So I end up with two jar files one with version and another without one. I can of course, change module name in Intellij settings to include version. But that will be reset whenever I change pom file.
Maybe somebody else had a better idea?
The jar name that Maven generates on disk is controlled by /project/build/finalName so if you edit your pom.xml to look like
<project>
...
<build>
...
<finalName>${artifactId}</finalName>
...
</build>
...
</project>
and then Maven will be generating the jar file without the version.
Note
finalName only controls the name of the file on disk. Once that file is transferred into the local repository cache or a remote repository it will be renamed to match the repository layout (i.e. ${artifactId}-${version}.${type} or ${artifactId}-${version}-${classifier}.${type} for artifacts with a classifier). You cannot change the format used by the repository.
I add the above note because the first thing everyone seems to want to do upon learning about the finalName parameter is try and change the name in the repository.
use version tag of the maven
<version>0.0.1-SNAPSHOT</version>
do not let intellij to create jar files without version tag.

maven skip/ignore parent tag

I wonder if it is possible to ignore parent tag in the pom.xml file. I need this because I have the following situation:
the structure is:
super root pom
root pom
module1 pom
module2 pom
module2.1 pom
module2.2 pom
module2.3 pom
I need to set super root pom as parent pom for root pom to make it availible to build it specifically on build server, but the trick is, that I don't have super root pom locally and need to ignore parent tag or do something not to be dependent on super parent pom. So, for example, I need to run root pom clean install independently from the super root pom. Is there any way to do this using some parameters or some pom.xml tricks?
Thanks everyone in advance!
If you have a corporate repo (Nexus, Artifactory...) The simpler would be to mvn deploy your parent, to make it available for all your projects, all your team, with no need of a local (relative file system path) relationship.

Maven: Selecting Parent Project Based On Profile

I have a maven project - it is a plugin for jenkins. It's parent should be a:
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.414</version>
</parent>
But at the same time this plugin can be also used for hudson, without changing any line of code. But the parent project for it should be:
<parent>
<groupId>org.jvnet.hudson.plugins</groupId>
<artifactId>hudson-plugin-parent</artifactId>
<version>2.0.1</version>
</parent>
Can I specify 2 different profiles for that and use them to build plugin for jenkins or hudson accordingly? So that I call something like that:
mvn package -P jenkins
or
mvn package -P hudson
I have tried to specify properties in profiles, but those are not replaced by their values inside the <parent> tag. So is there any other possibility to build plugin for both, but with as much as possible common code and files?
Added: So, if I cannot do that, what should I do then? How to refactor? What the new structure should be?
As already mentioned, this is not possible.
Also, it is not possible to set a property for the parent's version as the interpolation for that happens a lot earlier than the handling of the profiles.
I would suggest that you create a masterbuild project as follows:
master
|-plugin-jenkins
|-plugin-hudson
|-plugin-assembly
The master should build all three as usual. However, in the assembly, you could add each of the two plugins as dependencies in separate profiles. And... each of these plugins can have the parent you like.
This is obviously somewhat a deviation from the Maven convention, but I believe it is a solution to your problem.
It's not possible because the tag "parent" is not available in the profiles section of the pom.
Currently we decided to stick with 1 repository and 2 separate pom.xml files, giving maven key which pom.xml use to build the project.
mvn package -f pom-jenkins.xml
mvn package -f pom-hudson.xml
No you cannot do that. you will have to refactor somehow to avoid the necessity.
As mentioned already not possible. I would suggest to make separate projects for jenkins plugin and hudson plugin. I assume that in not that far future that will not work anymore cause Hudons and Jenkins will diverge.
In general, you should be able to set the {group,artifact}Id and version of the parent POM via Java System Properties or Environment Variables, but it seems there is a Bug in Maven which will only be fixed in 4.x:
https://issues.apache.org/jira/browse/MNG-624
Another solution is to delegate the inclusion of the parent POM to your own parent POMs which you reference in the relativePath element, and change the content of the target e.g. via a symlink or cp command.
So in the main POM you would write:
<parent>
<groupId>org.mycompany.project</groupId>
<artifactId>foo-artifact</artifactId>
<version>1.0.0</version>
<relativePath>./my-parent.pom</relativePath>
</parent>
And in my-parent-jenkins you would just put:
<groupId>org.mycompany.project</groupId>
<artifactId>foo-artifact</artifactId>
<version>1.0.0</version>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.414</version>
</parent>
The same project information with the block for hudson you put in my-parent-hudson.pom.
No you can either use
ln -s my-parent-jenkins.pom my-parent.pom
or
ln -s my-parent-hudson.pom my-parent.pom
to include the respective parent POM without the need to maintain two different main POM files for your project.
In case POM does not exist at the place referenced in relativePath, Maven will look up the POM in the remote repository[1], which is also an easy way to overwrite a parent POM locally.
[1] http://maven.apache.org/components/ref/3.3.9/maven-model/maven.html#class_parent

Resources