Running a task post maven install - maven-2

I want to run a simple exec command post maven install phase. What is the simplest way possible to achieve this? (without adding new plugins)

If you want to run this command as part of the normal build lifecycle, there is no other way than binding the exec goal on the install phase:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<id>my-exec</id>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
<inherited>false</inherited>
</execution>
</executions>
<configuration>
<executable>COMMAND</executable>
</configuration>
</plugin>
</plugins>
</build>
I did a simple test using the configuration above (using ls as "COMMAND") with a freshly created maven project and running mvn install produces the following output:
$ mvn install
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building maven-exec-testcase
[INFO] task-segment: [install]
[INFO] ------------------------------------------------------------------------
...
[INFO] [install:install {execution: default-install}]
[INFO] Installing /home/pascal/Projects/maven-exec-testcase/target/maven-exec-testcase-1.0-SNAPSHOT.jar to /home/pascal/.m2/repository/com/mycompany/app/maven-exec-testcase/1.0-SNAPSHOT/maven-exec-testcase-1.0-SNAPSHOT.jar
[INFO] [exec:exec {execution: my-exec}]
[INFO] pom.xml
[INFO] src
[INFO] target
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12 seconds
[INFO] Finished at: Tue Jan 05 19:26:04 CET 2010
[INFO] Final Memory: 11M/75M
[INFO] ------------------------------------------------------------------------
As we can see, the command is executed at the end of the install phase (after the copy of the artifact to the local repository).
And if you really don't want to add the snippet to your pom, then you'll have to explicitly call exec:exec after install on the command line as suggested by whaley.

The maven default lifecycle ends with the install and deploy goals - there is no pre- and post- version of those goals.
Potential options would be to:
Bind the exec:exec mojo to with the deploy phase. I would warn you against that idea as the deploy phase is really meant to deploy artifacts to a remote maven repository.
Run the exec:exec mojo after the install goal in your mvn invocation... e.g.:
mvn clean install exec:exec -Dexec.executable="yourcommand" -Dexec.args="arguments"
If you have a multi-module project, create another module at the end of your <modules> and bind exec:exec to any of the usual goals within that module. This will force this particular module to run last assuming other criteria the reactor looks at isn't met. A common strategy I employ with maven projects I work on is "when in doubt, create another module".

Related

how to configure selenium cucumber framework in GitLab pipeline using gitlab-ci.yml configuration file

I facing the below error while running the selenium cucumber project in GitLab pipeline, using .gitlab-ci.yml configuration
[ERROR] Failed to execute goal on project Samplemaven: Could not resolve dependencies for project org.example:Samplemaven:jar:1.0-SNAPSHOT: Failed to collect dependencies at io.cucumber:cucumber-java:jar:7.2.3: Failed to read artifact descriptor for io.cucumber:cucumber-java:jar:7.2.3: Could not transfer artifact io.cucumber:cucumber-java:pom:7.2.3 from/to central (http://repo.maven.apache.org/maven2): Connection reset -> [Help 1]
To run selenium cucumber project in GitLab, we need to setup this .gitlab-ci.yml file under the root folder. Use the below configuration in .gitlab-ci.yml file.
image: maven:3.8.3-openjdk-17
cache:
paths:
- .m2/repository/
- target/
build:
stage: build
script:
- mvn compile
test:
stage: test
script:
- pwd
- mvn test
Makes sure you have used the below plugin in pom.xml file,
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>8</source>
<target>8</target>
<debug>true</debug>
<debuglevel>lines,vars,source</debuglevel>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<includes>
<include>**/RunCukes*.java</include><!-- specify your runner file here -->
</includes>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</build>
Note: While running the pom.xml as maven test in your local IDE it should trigger the cucumber runner file

compilation error with apache giraph (building from the trunk)

===================Below is the error============================
[INFO] Building jar:
/home/rob/dev/apache/giraph-trunk/giraph/giraph-core/target/giraph-1.1.0-SNAPSHOT-for-hadoop-0.20.203.0-jar-with-dependencies.jar
[INFO] Total time: 1:12.383s
[INFO] Finished at: Mon Jan 20 17:25:46 PST 2014
[INFO] Final Memory: 31M/119M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project giraph-examples: Could not
resolve dependencies for project
org.apache.giraph:giraph-examples:jar:1.1.0-SNAPSHOT: Failure to find
org.apache.giraph:giraph-core:jar:tests:1.1.0-SNAPSHOT in
http://repo1.maven.org/maven2 was cached in the local repository,
resolution will not be reattempted until the update interval of
central has elapsed or updates are forced -> [Help 1]
I have hadoop installed on my machine but I am unable to build it.
thanks for looking into it.
It looks like you compile only the example project. You have to import parent project, core project and example project. Then to compile Giraph trunk for pure Yarn you can use:
clean package -P hadoop_yarn -Dhadoop.version=2.2.0 -DskipTests
BTW. what is your java version, maven version?

Maven Application got 5 Modules and 6 POM.xml files

I am working on existing Maven Project
Which has got 5 modules like
<modules>
<module>sideware</module>
<module>xmlmodule</module>
<module>business</module>
<module>service</module>
<module>helper</module>
</modules>
Each Module has got a one POM.xml file as well as
and one main Pom.xml
I am using Eclipse to run the POM.xml files as Maven install
Please tell me do i need to run the Each POM.xml indivudally ??
Or can i run the Parent POM.xml file once ??
Thank you
I think it is sufficient to run the parent POM. See the question What is the "reactor" in Maven? about the plugin that implements that for Maven. So you have the following options (at least):
Build the parent POM, which will build all modules as well.
Build a module individually, and it will build its dependencies automatically.
Here is a small experiment I have done on my own:
Build automatically == false.
Build a multi-module Maven project, and add there 2 modules.
Insert some code into the modules.
Run mvn install inside eclipse
As a result, I get the following output in the console:
[INFO] Scanning for projects...
[INFO] Reactor build order:
[INFO] MultiModuleExample
[INFO] Unnamed - com.tsi.mli:sideware:jar:0.0.1-SNAPSHOT
[INFO] Unnamed - com.tsi.mli:business:jar:0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] Building MultiModuleExample
[INFO] task-segment: [install]
[INFO] ------------------------------------------------------------------------
[INFO] [site:attach-descriptor {execution: default-attach-descriptor}]
[INFO] [install:install {execution: default-install}]
[INFO] Installing C:\projekte\setools-work\build\example-build-projekte\indigo-full\ws\multi-module-example\pom.xml to C:\Users\mliebelt\.m2\repository\com\tsi\mli\multi-module-example\0.0.1-SNAPSHOT\multi-module-example-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - com.tsi.mli:sideware:jar:0.0.1-SNAPSHOT
[INFO] task-segment: [install]
...
The directory structure I have got is:
multi-module-example/
business/
src/
target/
.classpath
.project
pom.xml
sideware/
...
src/
.project
pom.xml

How to query Pom version using maven

Is there a goal one can execute that will just echo the version of a pom? I can think of a way to make it work using the maven-ant-plugin, but that requires me to have ant-plugin configuration in the pom and I would like a method that would work with any pom.
mvn help:evaluate -Dexpression=project.version
If you want just the version echoed, and not the rest of the Maven "noise", you would use
mvn help:evaluate -Dexpression=project.version -q -DforceStdout

Maven: Missing: org.apache.maven.wagon:wagon-ftp:jar:1.0-rc1-SNAPSHOT

I'm new to Maven so I may be missing something obvious, but
I've got a maven project and when I try to "mvn package" this project it fails with
ERROR BUILD ERROR INFO
------------------------------------------------------------------------ [INFO] Failed to resolve artifact.
Missing:
---------- 1) org.apache.maven.wagon:wagon-ftp:jar:1.0-rc1-SNAPSHOT
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=org.apache.maven.wagon -DartifactId=wagon-ftp -Dversion=1.0-rc1-SNAPSHOT -Dpackaging=ja r -Dfile=/path/to/file
Alternatively, if you host your own repository you can deploy the file there:
mvn deploy:deploy-file -DgroupId=org.apache.maven.wagon -DartifactId=wagon-ftp -Dversion=1.0-rc1-SNAPSHOT -Dpackaging=jar
-Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
Path to dependency:
1) com.cgs:domain:jar:1.0-SNAPSHOT
2) org.apache.maven.wagon:wagon-ftp:jar:1.0-rc1-SNAPSHOT
----------
1 required artifact is missing.
for artifact: com.cgs:domain:jar:1.0-SNAPSHOT
from the specified remote repositories: ibiblio.org (http://mirrors.ibiblio.org/pub/mirrors/maven2)
The first thing I don't understand is the version it requires 1.0-rc1-SNAPSHOT. The projects' site says the current version is 1.0-beta-5. And I suppose beta goes before RC.
Anyway, I've tried to download the latest wagon-ftp JAR (1.0 beta 6 jar) and deploy it according to the instructions in the error message.
But guess what, this gave me the same error.
I've just found the solution as I was typing the end of this question.
The problem was that I was running "mvn install:install-file" from the same directory the failing project POM was in. It installed fine when I run it from another directory without a pom.xml.