Daniel
Daniel

Reputation: 604

How to pass maven command-line arguments to a inline Groovy script

I'm using the maven-release-plugin to release some artifacts. During the release:perform goal I would like to run a inline Groovy script which use my SCM credentials to proceed some tasks.

This is a snippet of my pom.xml

...     
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-release-plugin</artifactId>
  <version>2.4</version>
  <configuration>
    <goals>
      clean
      deploy
      org.codehaus.gmaven:gmaven-plugin:execute
    </goals>
  </configuration>
</plugin>
<plugin>
  <groupId>org.codehaus.gmaven</groupId>
  <artifactId>gmaven-plugin</artifactId>
  <version>1.3</version>
  <executions>
    <execution>
      <id>default-cli</id>
      <goals>
        <goal>execute</goal>
      </goals>
      <configuration>
        <source>
           log.info "Username: ${project.properties.username} account"
        </source>
      </configuration>
    </execution>
  </executions>
</plugin>
...

I invoke Maven as follow

mvn -B release:prepare release:perform -Dusername=foo -Dpassword=bar

And I gete the following output:

Username: null account

I tried to have a look at the Official GMaven page but it seems some snippets are missing...

Any idea?


EDIT

I finished by passing the credentials in the goals section

...     
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-release-plugin</artifactId>
  <version>2.4</version>
  <configuration>
    <goals>
      clean
      deploy
      org.codehaus.gmaven:gmaven-plugin:execute -Dusername=${username} -Dpassword=${password}
    </goals>
  </configuration>
</plugin>
...

The command line is till the same: mvn -B release:prepare release:perform -Dusername=foo -Dpassword=bar

As said by @khmarbaise it seems like the release cycle Maven is forked. I'm not sure it pass all the command-line arguments to the forked process. So doings this is like I'm forcing the forward of the CLI arguments.

Upvotes: 1

Views: 4357

Answers (2)

Mike y
Mike y

Reputation: 11

try adding to the gmavenplus-plugin configuration

"bindAllProjectProperties" and or "bindAllSessionUserProperties"

set to true

Upvotes: 0

khmarbaise
khmarbaise

Reputation: 97389

I would suggest to use the -Darguments= parameter of the maven-release-plugin, cause during the release cycle maven will be forked and that seemed to be the problem here.

Like this

mvn -B release:prepare release:perform -Darguments="-Dusername=foo -Dpassword=bar"

Take care on the quotes.

Upvotes: 2

Related Questions