Skip to content
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

Obtaining git.commit.id.abbrev from the command line via mvn-plugin:exec possible? #506

Closed
leonroy opened this issue Jul 10, 2020 · 2 comments
Milestone

Comments

@leonroy
Copy link

leonroy commented Jul 10, 2020

We have our tagged docker images being pushed to Docker hub with the following custom property app.docker.version.

<project>
    <artifactId>api-server</artifactId>
    <version>0.6.31-SNAPSHOT</version>

    <properties>
        <app.docker.version>${version}-${git.commit.id.abbrev}</app.docker.version>
    </properties>
...
</project>

We wanted to grab this property from the command line and pass it to our deploy step on the CI/CD server.

Running mvn -f api-server/pom.xml -q -Dexec.executable="echo" -Dexec.args='${app.docker.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec from the command line however returns null.

We can get the project.version just fine but not app.docker.version. Any ideas? (thanks)

@TheSnoozer
Copy link
Collaborator

Hello,
thank you for creating this issue.

Let me try to understand this correctly:
When trying to get the app.docker.version it returns null and not any variable (e.g. the outcome of ${version}-${git.commit.id.abbrev})?

If this is the case then that sounds like an issue with the org.codehaus.mojo:exec-maven-plugin and not this plugin. In general my suspect is that sounds related to running maven with a it's Plugin's Prefix (e.g. instead of mvn clean package you run with mvn clean org.codehaus.mojo:exec-maven-plugin:1.3.1:exec...). Within maven that might yield to surprises and the plugin properly needs to obtain the properties (e.g. checking System.getProperty). I can't recall the details what this plugin did, but as reference I'd point to

#413 (comment)
#444
#287

If this is not a bug in the plugin I'd suggest to open an issue for org.codehaus.mojo:exec-maven-plugin.

@TheSnoozer
Copy link
Collaborator

Just tested this locally and indeed this is a classical 'plugin' prefix problem.
Try running without the -q option to see what tasks are executed.

When running with mvn -Dexec.executable="echo" -Dexec.args='${app.docker.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec only the exec-task is being executed:

[INFO] Scanning for projects...
[INFO] 
[INFO] ---------< pl.project13.maven:git-commit-id-plugin-debugging >----------
[INFO] Building Git Commit Id Plugin Maven Mojo Debugging 0.0.3-SNAPSHOT
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] 
[INFO] --- exec-maven-plugin:1.3.1:exec (default-cli) @ git-commit-id-plugin-debugging ---
0.0.3-SNAPSHOT-null
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.824 s
[INFO] Finished at: 2020-07-14T22:15:43+02:00
[INFO] ------------------------------------------------------------------------

Where should the ${git.commit.id.abbrev} come from when the plugin is not even run?

You also need to add this plugin to the execution graph:

$ mvn -q -Dexec.executable="echo" -Dexec.args='${app.docker.version}' --non-recursive pl.project13.maven:git-commit-id-plugin:4.0.0:revision org.codehaus.mojo:exec-maven-plugin:1.3.1:exec
0.0.3-SNAPSHOT-beef4e9

or invoke it via the initialize lifecycle as such:

$ mvn -q -Dexec.executable="echo" -Dexec.args='${app.docker.version}' --non-recursive initialize org.codehaus.mojo:exec-maven-plugin:1.3.1:exec
0.0.3-SNAPSHOT-beef4e9

Since this is how maven is intended to work (by specifying the plugin prefix you want to run a specific mojo/task as outlined in https://maven.apache.org/guides/introduction/introduction-to-plugin-prefix-mapping.html) I'm going ahead and close this.

Feel free to reopen if you still have trouble getting this sorted.

@TheSnoozer TheSnoozer added this to the 4.0.1 milestone Jul 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants