I'm using maven-release-plugin version 2.4.1, and after executing goal mvn release:prepare -DpreparationGoals="clean deploy -Dmaven.test.skip"
I found that not only version of my application has been changed, but also it adds a space in confuguration in maven-antrun-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>initialize</phase>
<configuration>
<tasks>
<delete includeEmptyDirs="true" dir="com.project.HelloWorld"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Space added right between "com.project.HelloWorld" and slash. Issue lies in that fact, that xml-format-plugin remove this space after Maven build, but after each release I see this annoying space again.
Does anybody know why this happened or how to overcome this issue?
According to Extensible Markup Language (XML) 1.0 (Fifth Edition) – 3.1 Start-Tags, End-Tags, and Empty-Element Tags a white space character is absolutely OK:
Tags for Empty Elements
[44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>' [WFC: Unique Att Spec]
Annoying or not is a matter of POV, IMHO. I personally prefer them.
Related
I want my "pre-integration-test" phase to be the following execution of goals, in this specfic order.
PHASE : pre-integration-test
get a spring boot jar (maven-dependency-plugin:copy)
get-a-port (build-helper-maven-plugin:reserve-network-port)
display-port (maven-antrun-plugin:run #1)
start-server (exec-maven-plugin)
wait-for startup (maven-antrun-plugin:run #2)
Is there any way to do this using Maven 3?
The problem that I am facing, is that "maven-antrun-plugin:run" 1 & 2 will always be run one after the other, because they are defined in the same plugin element :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>display-port</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<echo>Displaying value of 'tomcat.http.port' property</echo>
<echo>[tomcat.http.port] ${tomcat.http.port}</echo>
</target>
</configuration>
</execution>
<execution>
<id>wait-for-startup</id>
<phase>pre-integration-test</phase>
<configuration>
<target>
<sleep seconds="10" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Right now, the only way I have found to do this is to duplicate the "maven-antrun-plugin:" plugin element in the pom file.
But this gets me a warning
'build.plugins.plugin.(groupId:artifactId)' must be unique but found duplicate declaration
For the scope of this question, I am not looking for a work-around, such as changing the plugin for the "display-port" or "wait-for startup", or changing the phase on of the goals.
I just want to understand if what I am trying to do is possible or not.
If multiple executions have the same phase, then the first one to be executed will be the built-in one (e.g. maven-compiler-plugin) whose id is default-something, then the other executions will take place in the order they appear in your pom file.
I am trying to replace maven exec with MavenInvokerPlugin because of problems on Jenkins with forwarding the maven settings file.
So in bash it looks straight:
mvn dependency:copy-dependencies#resolve-maven-deps
My translation to MavenInvokerPlugin configuration is
<plugin>
<artifactId>maven-invoker-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<projectsDirectory>${project.basedir}/src/main/docker</projectsDirectory>
<localRepositoryPath>${project.build.mavenDependencies}</localRepositoryPath>
<goal>dependency:copy-dependencies#resolve-maven-deps</goal>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>run</goal>
</goals>
<phase>compile</phase>
</execution>
</executions>
</plugin>
It looks like that execution id is completely ignored, because I tried random strings and mvn builds the project with success.
mvn dependency:copy-dependencies#asdfasdfa
So I'd like to know whether this feature is supported at all and what I am doing wrong.
P.S. I know that calling maven out of maven is anti pattern, but here is exactly that rare case when there is no other way.
After looking at projects using maven invoker I figured out the trick.
goal tag is not used, instead provide invokerPropertiesFile:
<pom>${project.basedir}/xxx/pom.xml</pom>
<invokerPropertiesFile>${project.basedir}/invoker.properties</invokerPropertiesFile>
content of the file:
invoker.goals=compile -P resolve-maven-deps
I have a file in my build that I want to put a UUID in every time a build is ran. I use maven's #my.property# to do this for other properties like project.version. What's the simplest way to have maven insert a universal unique identifier (UUID) similar to java.util.UUID does? (I'd rather not write a plugin if I can avoid it)
Edit: Actually, the buildNumber is not random per build but rather the git commit hash of the build. Coincidentally, I also needed this so it's helpful, but does not answer the question.
It appears the 'buildNumber' property does what I need. I'm going forward with that.
Maven property:
[echoproperties] buildNumber=fb08b44b310c489f5b170842d3aac3c5eb5a6f7b
In my file:
"uid": "fb08b44b310c489f5b170842d3aac3c5eb5a6f7b",
I used this plugin that prints all available properties (careful as some might differ - like env.* - between environments:
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<property environment="env" />
<echoproperties />
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
https://florianlr.wordpress.com/2012/04/24/16/
I am building three packages with rpm-maven-plugin. One parent, and two plugins that require the parent in the same version. Everything works fine, until I build it with XY-SNAPSHOT version. Then my rpm version gets truncated to XY part, but value of ${project.version} is still XY-SNAPSHOT.
It results in plugins requiring XY-SNAPSHOT version of parent, whereas I have installed XY version.
I wonder if I can use "truncated" version in "requires" section or force a plugin not to truncate my versions...
this is my configuration:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>rpm-maven-plugin</artifactId>
<version>2.0.1</version>
<executions>
<execution>
<id>parent-package</id>
<goals>
<goal>rpm</goal>
</goals>
<configuration>
<name>parent-package</name>
<mappings>
(...)
</mappings>
</configuration>
</execution>
<execution>
<id>first-plugin</id>
<goals>
<goal>rpm</goal>
</goals>
<configuration>
<name>first-plugin</name>
<mappings>
(...)
</mappings>
<requires>
<require>parent-package = ${project.version}</require>
</requires>
</configuration>
</execution>
<execution>
<id>second-plugin</id>
<goals>
<goal>rpm</goal>
</goals>
<configuration>
<name>second-plugin</name>
<mappings>
(...)
</mappings>
<requires>
<require>parent-package = ${project.version}</require>
</requires>
</configuration>
</execution>
</executions>
</plugin>
The RPM specification treats a - as a special character. See this is the best I could find in Google
The version number is used in version comparisons. The RPM comparison algorithm
is fairly complex, but can get fooled by strange version numbers. So, your best
bet is to stick to dotted numerics, such as 1.5 or 2.3.1.1.4 or 1.0. Version
numbers such as these will compare best from within the RPM system. For example:
Version: 1.1.2
You cannot use a dash in the version number, as RPM uses the dash to separate
the Name-Version-Release elements.
So a Maven version such as 1.0-SNAPSHOT would not be a valid RPM version number.
Mojo's RPM Maven Plugin does some transformations on the version number to “help” you. Specifically it strips out the -SNAPSHOT as you have found, and if there was a -SNAPSHOT it sets the rpm release to be SNAPSHOTyyyymmddHHMMSS (note the release is use to differentiate two different builds of the same version of an RPM)
What you need to do is get some properties set to the transformed version. There are a number of ways to do this. As I suggested in a comment you could use build-helper:regex-property to transform the property. The downside of this approach is that if the RPM plugin modifies the rules that it uses for version transformation your regex may leave you out of sync.
The correct solution is to use the rpm:version goal to set the rpm.version property for you, so your configuration becomes:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>rpm-maven-plugin</artifactId>
<version>2.0.1</version>
<executions>
<execution>
<id>properties</id>
<goals>
<goal>version</goal>
</goals>
</execution>
<execution>
<id>parent-package</id>
<goals>
<goal>rpm</goal>
</goals>
<configuration>
<name>parent-package</name>
<mappings>
(...)
</mappings>
</configuration>
</execution>
<execution>
<id>first-plugin</id>
<goals>
<goal>rpm</goal>
</goals>
<configuration>
<name>first-plugin</name>
<mappings>
(...)
</mappings>
<requires>
<require>parent-package = ${rpm.version}</require>
</requires>
</configuration>
</execution>
<execution>
<id>second-plugin</id>
<goals>
<goal>rpm</goal>
</goals>
<configuration>
<name>second-plugin</name>
<mappings>
(...)
</mappings>
<requires>
<require>parent-package = ${rpm.version}</require>
</requires>
</configuration>
</execution>
</executions>
</plugin>
If you need the property to have a different name just use the versionProperty configuration parameter, but keep in mind that with multiple executions you probably want to leave it to its defaults
To expand a bit on #StephenConnolly's excellent answer, the maven and rpm versioning strategies have some specific differences. The differences are mostly around maven's version qualifier and rpm's build (or release) attribute.
Maven treats any version without a qualifier as being newer than a version without a qualifier. Maven also has special handling for any qualifier which ends with SNAPSHOT. RPM on the other hand requires a build number and compares on that value. Not surprisingly, rpm has no special logic for SNAPSHOT.
Since we are working in maven, we need to follow maven's rules/behavior and determine how to massage values in rpm to make that work. What this means is that we need to establish rules for massaging the rpm release value to achieve the following based on maven qualifiers:
1.0-alpha-1-SNAPSHOT
1.0-alpha-1
1.0-alpha-2
1.0-beta-1
1.0-SNAPSHOT
1.0
Additionally, we want multiple SNAPSHOT builds of rpms to be able to identify newer (by build date) and upgrade correctly.
The documentation for the release attribute describe the rules to achieve this desired behavior.
You are welcome to override this default behavior, but I would caution you to be very careful about being sure that rpm being built with identical metadata (arch, os, version, release) contain identical content.
I'd like to rename all dependencies to strip off SNAPSHOT so my file handling scripts and installer don't break when I release.
I presently, use maven-dependency-plugin:copy-dependencies and copy with individual artifacts listed and renamed. I'd rather have something akin to ant's regex mapper establish a renaming rule.
Presently, I plan to copy-dependencies to 1st stage directory in prepare-package and use antrun's copy + regex mapper in package to copy/rename but that wastes time and space.
Is there a more direct way to approach this problem? Can the dependency plugin handle rule based renames?
Thanks
Peter
If you just want to remove the version from the dependencies, then add the stripVersion parameter to the plugin configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy-dependencies</id>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<silent>true</silent>
<outputDirectory>libs</outputDirectory>
<stripVersion>true</stripVersion>
<includeTypes>swc</includeTypes>
<excludeGroupIds>com.adobe.flex.framework</excludeGroupIds>
<excludeTypes>pom</excludeTypes>
</configuration>
</execution>
</executions>
</plugin>