JVM Parallel Plugin Issue "Nothing to compile - all classes are up to date" - cucumber-jvm

I have attached my sample project structure, you can check the package name is also correct, my compiler and jre are of same version.`
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) # CucumberTest ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- cucumber-jvm-parallel-plugin:5.0.0:generateRunners (generateRunners) # CucumberTest ---
[INFO] Adding C:\Users\Bismillah\Documents\workspace-spring-tool-suite-4-4.9.0.RELEASE\CucumberTest\target\generated-test-sources\cucumber to test-compile source root
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # CucumberTest ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.5.1:testCompile (default-testCompile) # CucumberTest ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to C:\Users\Bismillah\Documents\workspace-spring-tool-suite-4-4.9.0.RELEASE\CucumberTest\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:3.0.0-M3:test (default-test) # CucumberTest ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.204 s
[INFO] Finished at: 2020-12-19T19:13:30+05:30
[INFO] ------------------------------------------------------------------------
My POM.XML
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.selenium.try</groupId>
<artifactId>CucumberTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<compilerVersion>1.8</compilerVersion>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<parallel>methods</parallel>
<threadCount>2</threadCount>
<perCoreThreadCount>false</perCoreThreadCount>
<testFailureIgnore>true</testFailureIgnore>
<includes>
<include>**/*IT.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>com.github.temyers</groupId>
<artifactId>cucumber-jvm-parallel-plugin</artifactId>
<version>5.0.0</version>
<executions>
<execution>
<?m2e ignore?>
<id>generateRunners</id>
<phase>generate-test-sources</phase>
<goals>
<goal>generateRunners</goal>
</goals>
<configuration>
<!-- Mandatory -->
<!-- List of package names to scan for glue code. -->
<glue>com.example</glue>
<!-- These are optional, with the default values -->
<!-- Where to output the generated tests -->
<outputDirectory>${project.build.directory}/generated-test-sources/cucumber</outputDirectory>
<!-- The directory, which must be in the root of the runtime classpath,
containing your feature files. -->
<featuresDirectory>src/test/resources/FeatureFiles/</featuresDirectory>
<!-- Directory where the cucumber report files shall be written -->
<cucumberOutputDir>target/cucumber-parallel</cucumberOutputDir>
<plugins>
<plugin>
<name>json</name>
</plugin>
</plugins>
<tags>
<tag>#tag1</tag>
</tags>
<!-- Generate TestNG runners instead of JUnit ones. -->
<useTestNG>false</useTestNG>
<!-- The class naming pattern to use. Only required/used if naming
scheme is 'pattern'. -->
<namingPattern>Parallel{c}IT</namingPattern>
<!-- One of [SCENARIO, FEATURE]. SCENARIO generates one runner per
scenario. FEATURE generates a runner per feature. -->
<parallelScheme>FEATURE</parallelScheme>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>4.2.3</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>4.2.6</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>4.2.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>4.3.0</version>
</dependency>
</dependencies>
</project>
enter image description here
Test Resources are not getting generated and my scripts are not getting identified, i have tried multiple solutions. can any one help me on this.enter image description here

As per the POM structure you have given ,include tag is as below-
<includes>
<include>**/*IT.java</include>
</includes>
But as per the project structure your testrunner name is RunnerClass.java, so that
should be`inside include tag. Seems you have copied the settings from the lick below
but forgot to modify it.`
https://maven.apache.org/surefire/maven-failsafe-plugin/examples/inclusion-exclusion.html

Related

Running Karate tests from commandline returns surefire-plugin error

I've been trying to run my .feature karate files from command line. I've been trying to follow the docs, so that I've found below instruction:
mvn test -Dtest=CatsRunner
When I run above command, I see that my tests are running, and all of them are passing. However, there are some errors being popped up at the end of my command line. Below is the log part:
1 Scenarios (1 passed)
16 Steps (16 passed)
0m2.388s
Karate version: 0.8.0
html report: (paste into browser to view)
-----------------------------------------
file:/D:/Dev/xxx/yyy/karate/target/surefire-reports/TEST-tvplus.singleuseroperations.authenticate.auth-existing-IPTV-user.html
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 4.302 s - in tvplus.singleuseroperations.authenticate.AuthenticateRunner
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 14.204 s
[INFO] Finished at: 2018-12-12T15:50:06+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.1:test (default-test) on project karate: No tests were executed!
(Set -DfailIfNoTests=false to ignore this error.) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1]
http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
I am also pasting my pom file below:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.xxx.yyy.zzz</groupId>
<artifactId>karate</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<maven.compiler.version>3.6.0</maven.compiler.version>
<karate.version>0.8.0</karate.version>
<jdbc.version>5.1.3.RELEASE</jdbc.version>
<maven.surefire.version>2.22.1</maven.surefire.version>
</properties>
<dependencies>
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-apache</artifactId>
<version>${karate.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-junit4</artifactId>
<version>${karate.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${jdbc.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-testng</artifactId>
<version>${karate.version}</version>
</dependency>
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-core</artifactId>
<version>${karate.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
</dependency>
</dependencies>
<build>
<testResources>
<testResource>
<directory>src/test/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<configuration>
<encoding>UTF-8</encoding>
<source>${java.version}</source>
<target>${java.version}</target>
<compilerArgument>-Werror</compilerArgument>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.version}</version>
<configuration>
<argLine>-Dfile.encoding=UTF-8</argLine>
</configuration>
</plugin>
</plugins>
</build>
Also, here is my CatsRunner.java:
package xyz;
import com.intuit.karate.junit4.Karate;
import cucumber.api.CucumberOptions;
import org.junit.runner.RunWith;
#RunWith(Karate.class)
#CucumberOptions(features = "classpath:xxx/singleuseroperations/authenticate/auth-existing-user.feature")
public class CatsRunner {
}
EDIT: Below part is not related with the question. No need to think about it. Upgrading karate version solved the problem.
I've been using #CucumberOptions at the top of my runner class since I've encountered some trouble when adding #KarateOptions annotation to my code.
Thanks in advance.
To eliminate the surefire-plugin error, you may want to add DfailIfNoTests=false to your command line run script. Surefire pluging integrates with the tests you've written. This option will compile and run your tests, but not fail the whole build if some of the tests fail.
The #KarateOptions is available only in 0.9.0: https://github.com/intuit/karate/releases/tag/v0.9.0
EDIT: If you simplify your pom.xml and avoid using things not needed for Karate you will be able to solve the problem with "surefire-plugin". This is what I have been trying to explain by pointing you to this link: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

Using jdbcdslog or log4jdbc with maven2

I'm trying to use jdbcdslog or log4jdbc with maven2. - I want to log all SQL that is executed by mvn-sql.
I installed slf4j-api (1.6.1), slf4j-log4j12 (1.6.1) and jdbcdslog (1.0.5) Jars to my local maven2-repo and configured in my pom.xml the following:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>1.3</version>
<dependencies>
<dependency>
<groupId>jdbcdslog</groupId>
<artifactId>jdbcdslog</artifactId>
<version>1.0.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>9.0.2.0.0</version>
</dependency>
</dependencies>
<configuration>
<driver>org.jdbcdslog.DriverLoggingProxy</driver>
</configuration>
<executions>
<execution>
...
<configuration> <url>jdbc:jdbcdslog:oracle:thin:#myurl.com:1521:TEST;targetDriver=oracle.jdbc.driver.OracleDriver</url>
...
</configuration>
</execution>
</executions>
</plugin>
Executing this leads to:
java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at org.jdbcdslog.DriverLoggingProxy.(DriverLoggingProxy.java:16)
Same error occurs using log4jdbc. Has anyone a glimpse about that problem?
Thanks & kind regards,
Hanno
I couldn't reproduce the problem. With the following configuration (using the "simple" binding):
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>1.3</version>
<dependencies>
<dependency>
<groupId>jdbcdslog</groupId>
<artifactId>jdbcdslog</artifactId>
<version>1.0.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbyclient</artifactId>
<version>10.5.3.0_1</version>
</dependency>
</dependencies>
<configuration>
<driver>org.jdbcdslog.DriverLoggingProxy</driver>
<url>jdbc:jdbcdslog:derby://localhost:1527/Q3854037-1.0-SNAPSHOT;targetDriver=org.apache.derby.jdbc.ClientDriver</url>
<username>APP</username>
<password>APP</password>
</configuration>
<executions>
<execution>
<id>drop-db-before-test-if-any</id>
<phase>process-test-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<autocommit>true</autocommit>
<sqlCommand>select * from FOO</sqlCommand>
<!-- ignore error when database is not avaiable -->
<onError>continue</onError>
</configuration>
</execution>
</executions>
</plugin>
Running mvn test just works
$ mvn test
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Q3854037
[INFO] task-segment: [test]
[INFO] ------------------------------------------------------------------------
...
[INFO] Executing commands
821 [main] INFO org.jdbcdslog.StatementLogger - java.sql.Statement.execute select * from FOO 100 ms. at org.codehaus.mojo.sql.SqlExecMojo.execSQL(SqlExecMojo.java:815)
[INFO] 1 of 1 SQL statements executed successfully
...
Sure, I'm using another SLF4J binding but I don't think this difference is relevant (even with the binding for log4j, I could not reproduce the NoClassDefFoundError). Maybe check that your SLF4J jar is not corrupted (re-download it). By the way, you're missing a dependency on log4j as logging framework.

Maven - pass argument to use in exec-maven-plugin

in my pom I've added the exec-maven-plugin to call a java class which will generate a file. This class requires some parameters to be passed to the main method, one of those is the location of an input file (outside the project). Until now I've been using a relative path for this which works fine:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.laco.projectmaster.util.LanguageGenerator</mainClass>
<arguments>
<argument>../PM-Config/dev/PMLanguage.xls</argument>
<argument>PM4.0</argument>
<argument>${project.build.outputDirectory}/com/laco/projectmaster/props/resources</argument>
<argument>ProjectMaster</argument>
<argument>Created during maven build (POM Version: ${pom.version})</argument>
</arguments>
</configuration>
</plugin>
Now I'm starting to use hudson to install/package and deploy the wars and I cannot longer use this relative path. Simple I thought, I just pass the location of the input file when invoking maven like:
mvn clean package -Dlangdir=C:/somedir
and then alter the pom like:
<argument>${langdir}/PMLanguage.xls</argument>
However, this parameter simply gets ignored here. The path the main class receives as argument becomes null/PMLanguage.xls . The parameter itself is available in maven, I tested with succes using an echo in the antrun plugin. The correct path was echoed.
Are the paremeters you pass to maven then not available by default no matter where you reference them in the pom?
thanks for any help,
Stijn
I can't reproduce the issue. I used the following test class:
package com.stackoverflow.q3421918;
public class Hello
{
public static void main( String[] args )
{
System.out.println( args[0] + " " + args[1] );
}
}
And the following pom.xml:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.stackoverflow.q3421918</groupId>
<artifactId>Q3421918</artifactId>
<version>1.0-SNAPSHOT</version>
<!-- this was a test for a workaround -->
<properties>
<myprop>${langdir}</myprop>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.stackoverflow.q3421918.Hello</mainClass>
<arguments>
<argument>${myprop}</argument>
<argument>${langdir}</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</project>
And here is the output I get:
$ mvn clean package -Dlangdir=C:/somedir
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Q3421918
[INFO] task-segment: [clean, package]
[INFO] ------------------------------------------------------------------------
...
[INFO] Preparing exec:java
[WARNING] Removing: java from forked lifecycle, to prevent recursive invocation.
[INFO] No goals needed for project - skipping
[INFO] [exec:java {execution: default}]
Hello c:/somedir c:/somedir
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
...
Tested with Maven 2.2.1.

properties-maven-plugin: Error loading properties-file

I want to extract all the properties from my pom.xml into a properties-file. These are the common properties like dependency-versions, plugin-versions and directories.
I'm using the properties-maven-plugin, but its not working as i want it to.
The essential part of my pom.xml:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-1</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${basedir}/pom.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
Now when i run "mvn properties:read-project-properties" i get the following error:
[INFO] One or more required plugin parameters are invalid/missing for 'properties:read-project-properties'
[0] Inside the definition for plugin 'properties-maven-plugin' specify the following:
<configuration>
...
<files>VALUE</files>
</configuration>.
The pom.properties-file is located in the same dir as the pom.xml.
What can i do to let the properties-maven-plugin read my properties-file?
EDIT
I filed an issue at http://jira.codehaus.org/browse/MOJO-1523.
It has been closed as "not a bug", the reason is:
It's by design. The project definition
has to be self-contained, otherwise it
is no longer complete if it is refered
from elsewhere as part of the
transitive deps.
Your configuration element is defined inside an execution and thus applies to this execution only.
So either call mvn initialize (or a phase posterior to initialize) to use the configuration of your current execution binding.
Or use a global configuration:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<configuration>
<files>
<file>etc/config/dev.properties</file>
</files>
</configuration>
...
</plugin>
And then call
mvn properties:read-project-properties
But that wouldn't make much sense in the particular case of this plugin (you want the properties to be available during the build) so this leaves you with the first solution.
Update: I did a test on my side and, indeed, with the following POM:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.stackoverflow</groupId>
<artifactId>Q2664362</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>etc/config/dev.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Running mvn test won't work: maven will try to download junit:jar:${junit.version} (i.e. it doesn't use the value of the property) and this will obviously fail.
$ mvn test
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building SO - Q2664362 - maven-properties-plugin demo
[INFO] task-segment: [test]
[INFO] ------------------------------------------------------------------------
[INFO] [properties:read-project-properties {execution: default}]
[INFO] [resources:resources {execution: default-resources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/pascal/Projects/stackoverflow/Q2664362/src/main/resources
Downloading: http://repo1.maven.org/maven2/junit/junit/${junit.version}/junit-${junit.version}.pom
[INFO] Unable to find resource 'junit:junit:pom:${junit.version}' in repository central (http://repo1.maven.org/maven2)
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources {execution: default-testResources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/pascal/Projects/stackoverflow/Q2664362/src/test/resources
Downloading: http://repo1.maven.org/maven2/junit/junit/${junit.version}/junit-${junit.version}.jar
[INFO] Unable to find resource 'junit:junit:jar:${junit.version}' in repository central (http://repo1.maven.org/maven2)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.
...
The odd part is that the download of the dependency occurs after properties:read-project-properties. I'm not sure but this sounds like a bug, you should open an issue.
Try using validate phase instead of initialize for maven 3.x (link).
EDIT2
See here for a workaround using Ant Tasks, which makes this use case possible
I encounter your question, but i tried to add this resources here, it works well.
<build>
<resources>
<resource>
<directory>src/config</directory> //your config folder
<filtering>true</filtering>
</resource>
</resources>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>src/config/config.properties</file> //your config file
</files>
</configuration>
</execution>
</executions>
</plugin>
</build>
Hope you resolve this as above

Can I use the path to a Maven dependency as a property?

I have a maven dependency in my pom.xml as such:
<dependency>
<groupId>com.foo</groupId>
<artifactId>Bar</artifactId>
<version>1.2.3</version>
</dependency>
And I would like to use the system path to the binary as a property (so I can pass it to an external process that is kicked off by maven). I can do this in an awkward way:
<properties>
<my.lib>${settings.localRepository}/com/foo/Bar/1.2.3/Bar.jar</my.lib>
</properties>
But I would really like to use a more standard mechanism, such as:
<properties>
<my.lib>${com.foo:Bar:1.2.3}</my.lib>
</properties>
I something like that possible?
Here is a correct implementation, using the maven-dependency-plugin properties goal, which can be used anywhere in a pom:
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.stackoverflow</groupId>
<artifactId>q2359872</artifactId>
<version>2.0-SNAPSHOT</version>
<name>q2359872</name>
<properties>
<!-- Must be listed in the dependencies section otherwise it will be null. -->
<my.lib>${org.jmockit:jmockit:jar}</my.lib>
</properties>
<dependencies>
<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
<version>1.11</version>
</dependency>
</dependencies>
<build>
<defaultGoal>generate-sources</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<goals>
<goal>properties</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Example usage: -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
<phase>generate-sources</phase>
</execution>
</executions>
<configuration>
<executable>echo</executable>
<arguments>
<argument>path to jar=</argument>
<argument>${org.jmockit:jmockit:jar}</argument>
<argument>my.lib=</argument>
<argument>${my.lib}</argument>
</arguments>
</configuration>
</plugin>
<!-- end of Example usage -->
</plugins>
</build>
</project>
And the output is...
jpyeron#black /projects/wkspc/tmp/foo
$ /cygdrive/c/programs.x86_64/apache-software-foundation/apache-maven-3.1.1/bin/mvn
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building q2359872 2.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.3:properties (default) # q2359872 ---
[INFO]
[INFO] --- exec-maven-plugin:1.2:exec (default) # q2359872 ---
path to jar= C:\Documents and Settings\jpyeron\.m2\repository\org\jmockit\jmockit\1.11\jmockit-1.11.jar my.lib= C:\Documents and Settings\jpyeron\.m2\repository\org\jmockit\jmockit\1.11\jmockit-1.11.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.032s
[INFO] Finished at: Wed Sep 17 12:07:18 EDT 2014
[INFO] Final Memory: 10M/153M
[INFO] ------------------------------------------------------------------------
Assuming that the com.foo:Bar:jar:1.2.3 artifact is declared as dependency in your POM, the following property returns the path to the jar in the local repository:
${maven.dependency.com.foo.Bar.jar.path}
Update: Here is a simple POM demonstrating this:
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.stackoverflow</groupId>
<artifactId>q2359872</artifactId>
<version>1.0-SNAPSHOT</version>
<name>q2359872</name>
<properties>
<my.lib>${maven.dependency.junit.junit.jar.path}</my.lib>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>process-resources</phase>
<configuration>
<tasks>
<echo>${my.lib}</echo>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Running mvn process-resources produces the following output:
$ mvn process-resources
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building q2359872
[INFO] task-segment: [process-resources]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources {execution: default-resources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/pascal/Projects/stackoverflow/q2359872/src/main/resources
[INFO] [antrun:run {execution: default}]
[INFO] Executing tasks
[echo] /home/pascal/.m2/repository/junit/junit/3.8.1/junit-3.8.1.jar
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7 seconds
[INFO] Finished at: Tue Mar 02 14:41:32 CET 2010
[INFO] Final Memory: 7M/68M
[INFO] ------------------------------------------------------------------------
There is a plugin which might be what you are looking for... bitstrings.org (home).
If none of the upper work, you can always use gmaven to agressively dive into MavenProject object and get your artifact infos. In my case, I had the following artifact declared in a profile :
<!-- Neo4J connector. This dependency is scoped to be usable by maven-exec-plugin
which installs it in Glassfish -->
<dependency>
<groupId>com.netoprise</groupId>
<artifactId>neo4j-connector</artifactId>
<version>${neo4j.connector.version}</version>
<type>rar</type>
<!-- Set in test scope to avoid release issues -->
<scope>test</scope>
</dependency>
To get its path and put it in a maven property, I wrote the following gmaven script :
<!-- Small script used to build maven property for neo4j-connector path -->
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>get-neo4j-connector-rar-path</id>
<phase>validate</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
<![CDATA[
println "initial value of neo4j.connector.rarPath is \""+project.properties['neo4j.connector.rarPath']+"\""
// Duplicate model in a Mavenproject, allowing me to get associated artifact
// So sad I can't get the embdder object
// More info here : http://maven.apache.org/ref/3.0.3/maven-core/apidocs/org/apache/maven/project/MavenProject.html
def mavenProject = new org.apache.maven.project.MavenProject(project)
// More infos on Artifact there : http://maven.apache.org/ref/3.0.3/maven-artifact/apidocs/org/apache/maven/artifact/Artifact.html
def neo4jConnector = mavenProject.getArtifacts().find { artifact -> artifact.getArtifactId()=='neo4j-connector' }
// Now resolve dependency to produce an artifact
// notice maven property interpolation doesn't do toString, so we have to do it ourselves
project.properties['neo4j.connector.rarPath'] = neo4jConnector.getFile().getAbsolutePath()
println "usable neoj4Connector can be found at "+project.properties['neo4j.connector.rarPath']
]]>
</source>
</configuration>
</execution>
</executions>
</plugin>
It's some kind of brute-force method, but it DO work far better than the previous solutions I've seen there.
You need to write a new maven plugin that sets a property value to the fully-resolved pathname of a dependency. The maven-dependency-plugin won't do that for you.
It will copy your dependency somewhere and then you can refer to it by that pathname.