-
Notifications
You must be signed in to change notification settings - Fork 301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Properties in pom are not resolved for maven-install-plugin #256
Comments
This is very likely to be resolved by what is explained in the readme:
|
Thanks for your response. Unfortunately, this doesn't help. But my project is not a multi-module project anyway. |
Have you played around with phases? |
I'm not sure, what exactly do you want me to try out. Changing the phase of the revision-goal? By the way, I'm using version 2.2.1. |
Ad to the configuration of the git plugin the following <plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<dateFormat>yyyyMMdd-HHmmss</dateFormat>
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
<generateGitPropertiesFile>false</generateGitPropertiesFile>
<injectAllReactorProjects>true</injectAllReactorProjects>
</configuration>
</plugin> Also what happens if you set the <build>
<finalName>${git.commit.time}.${git.commit.id.abbrev}</finalName>
</build> ? |
Thanks for your response. Unfortunately, setting injectAllReactorProjects and the finalName doesn't help. |
I used previous version of plugin, but maybe you should try add part with
|
Hi aszka, |
The build log seems to indicates the issue here:
Change the <project ....>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.number>${git.commit.time}.${git.commit.id.abbrev}</version.number>
</properties>
<build>
<finalName>${version.number}</finalName>
<plugins>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<dateFormat>yyyyMMdd-HHmmss</dateFormat><!-- human-readable part of the version id -->
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
<generateGitPropertiesFile>false</generateGitPropertiesFile><!-- somehow necessary. otherwise the variables are not available in the pom -->
<injectAllReactorProjects>true</injectAllReactorProjects>
</configuration>
</plugin>
...... Can't build this specific project since I don't have docker, but have tested with a similar project where I could reproduce the problem. Hope it helps. |
Hi TheSnoozer, thanks for your help and feedback! The point is that I can specify the jar name with The output is something like this:
|
Hi, In short: maven-install-plugin will not take finalName into account! On top using a dynamic version number like I would quote from https://issues.apache.org/jira/browse/MINSTALL-30
At this stage I feel that this is not a problem of the git-commit-id-plugin it's a general maven / maven-install-plugin issue.... Use recommended steps with finalName from above and add the the following plugins: <plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>default-install</id>
<phase>install</phase>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>default-install</id>
<phase>install</phase>
<goals>
<goal>install-file</goal>
</goals>
</execution>
</executions>
<configuration>
<file>${project.basedir}/target/${artifactId}-${version.number}.${project.packaging}</file>
<groupId>de.philipphauer.blog</groupId>
<artifactId>versioning-continuous-delivery</artifactId>
<version>${artifactId}-${version.number}</version>
<packaging>jar</packaging>
</configuration>
</plugin> You would need to overwrite and skip the default install-Plugin otherwise you would install a version as specified in the
Full pom that I used can be obtained from here: |
I am having the same issue exactly. |
Please review my last comment in this issue here: This specific behaviour is basically not intended / not supported by maven-install-plugin and maven-deploy-plugin (https://issues.apache.org/jira/browse/MDEPLOY-93). The naming format in the remote repo is always $artifactId-$version-$classifier by default. However as outlined in my previous comment you can override the configuration from plugins and use install-file mojo for maven-install-plugin or deploy-file mojo for maven-deploy-plugin (example): maven-install-plugin <plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>default-install</id>
<phase>install</phase>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>default-install</id>
<phase>install</phase>
<goals>
<goal>install-file</goal>
</goals>
</execution>
</executions>
<configuration>
<file>${project.basedir}/target/${artifactId}-${version.number}.${project.packaging}</file>
<groupId>de.philipphauer.blog</groupId>
<artifactId>versioning-continuous-delivery</artifactId>
<version>${artifactId}-${version.number}</version>
<packaging>jar</packaging>
</configuration>
</plugin> read more here: https://maven.apache.org/plugins/maven-install-plugin/ deploy-install-plugin <plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
</execution>
</executions>
<configuration>
<file>${project.basedir}/target/${version.number}.${project.packaging}</file>
<groupId>de.philipphauer.blog</groupId>
<artifactId>versioning-continuous-delivery</artifactId>
<version>${artifactId}-${version.number}</version>
<packaging>jar</packaging>
<url>ftp://user:12345@localhost/</url>
</configuration>
</plugin> Please note that the url from the maven-deploy-plugin contains a username / password for testing purposes. read more here: https://maven.apache.org/plugins/maven-deploy-plugin/ DisclaimerI would outline that this is just a sample configuration on how it can be done and would strongly advice not to use a pattern that is not build-in within maven. |
Thanks for you update @TheSnoozer. That provided a possible solution moving forward. |
Hey guys, I think I found another solution, could you verify, if this is practicable to? // from org.apache.maven.plugin.install.InstallMojo and org.apache.maven.plugins.deploy.DeployMojo:
@Parameter( defaultValue = "${project}", readonly = true, required = true )
private MavenProject project; And the This will work with pom packaging and is less configuration. The solution will overwrite the version during build-time with the commit hash from the git-commit-id-plugin. It uses the groovy-maven-plugin, so all other plugins especially the install and deploy plugin, will get the right version. <plugin>
<!-- retrieve the current commit hash, for versioning the poms and artifacts -->
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>2.2.4</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<skipPoms>false</skipPoms>
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
</configuration>
</plugin>
<plugin>
<!-- sets the version for each pom including children pom -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>set</goal>
</goals>
<inherited>false</inherited>
<configuration>
<!-- comes from the git-commit-id-plugin -->
<newVersion>${git.commit.id}</newVersion>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<!-- this will change the version for the current build, so the artifacts will be installed and deployed with the corret version -->
<groupId>org.codehaus.gmaven</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>project.artifact.version='${git.commit.id}';</source>
</configuration>
</execution>
</executions>
</plugin>``` |
Hi, thanks for the additional input. |
This would not overwrite any references. Only the version of the reference. |
Ohh I SEE....sorry for misunderstanding...what you said is basically another solution to achieve the same with the mvn install plugin....maven is such a pain sometimes...thanks for your suggestion and debugging session ;-) |
Yeah but my solution works for pom projects and multi-module-projects. So my solution is a better approach for my problem. |
The issues you are encountering here are due to maven evaluating the version tags well before firing any of your plugin code. You might want to check out the New'ish maven 3.5 revision and changelist feature, this could go really well with this plugin. But note that you will also have to "flatten" your pom file(s) before install and deploy otherwise they will unusable (as mentioned in the link above and painfully experienced in practice). |
Thanks for the additional input....I can remember that with old maven versions you could set dynamic versions with properties where I was exactly using something along the lines |
@bertramn This is nice idea, but flatten don't see any of maven-git-commit-id-plugin variables :( |
blow is my version: ...
<version>${revision}</version>
...
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>2.2.4</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<phase>validate</phase>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<injectAllReactorProjects>true</injectAllReactorProjects>
<!-- use commit date as version: '$major.$minor.$incr' -->
<dateFormat>yyyy.MM.dd</dateFormat>
<!-- configure git-describe to produce '${abbr-sha1}' or '${abbr-sha1}-SNAPSHOT' -->
<gitDescribe>
<always>true</always>
<dirty>-SNAPSHOT</dirty>
<match>__null__</match>
</gitDescribe>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>change-version</id>
<phase>validate</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<scripts>
<script><![CDATA[
import org.apache.maven.artifact.versioning.VersionRange;
git_revision = '${git.commit.time}-${git.commit.id.describe}'
if (! project.properties['revision']?.trim()) {
println 'Change `version` to ' + git_revision
System.properties['revision'] = git_revision
project.properties['revision'] = git_revision
project.properties['project.version'] = git_revision
project.properties['git.build.version'] = git_revision
project.version = git_revision
project.artifact.version = git_revision
project.artifact.versionRange = VersionRange.createFromVersion(git_revision)
}
]]></script>
</scripts>
</configuration>
</execution>
<!-- for debug: -->
<!--
<execution>
<id>dump-version</id>
<phase>package</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<scripts>
<script><![CDATA[
println System.properties['revision']
println '${revision}'
println '${project.version}'
println '${git.build.version}'
println project.version
println project.artifact
println project.artifact.version
println project.artifact.versionRange
]]></script>
</scripts>
</configuration>
</execution>
-->
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.14</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.0.1</version>
<configuration>
<!-- <flattenMode>ossrh</flattenMode> -->
<flattenedPomFilename>.flattened-pom.xml</flattenedPomFilename>
<outputDirectory>${project.build.directory}</outputDirectory>
<updatePomFile>true</updatePomFile>
</configuration>
<executions>
<execution>
<id>flatten</id>
<phase>initialize</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
|
Hi,
I try to use the Git commit hash (and the commit timestamp) as the version number for my built artifact.
mvn package
works fine. It creates a myapp-20160702-180249.193a613.jar.However, "mvn install" doesn't seem to resolve the dynamic properties of the git-commit-id-plugin (like ${git.commit.time} and ${git.commit.id.abbrev}). Output:
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ versioning-continuous-delivery --- [INFO] Installing <projectdir>/target/app-20160702-180249.193a613.jar to <userhome>/.m2/repository/<path>/app/${git.commit.time}.${git.commit.id.abbrev}/app-${git.commit.time}.${git.commit.id.abbrev}.jar
Same problem for "mvn deploy".
My pom.xml:
Basically, it seems that properties are resolved (like ${version.number}), but not the one created by the git-commit-id-plugin (${git.commit.id.abbrev}). That's why I'm posting this issue here.
Cheers Philipp
The text was updated successfully, but these errors were encountered: