Does requireProperty not require a typical maven property in maven enforcer? - maven

I am trying to require that a particular property is defined during the build using the maven enforcer plugin and the RequireProperty rule.
The relevant part of my pom.xml is this.
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<properties>
<foo>bar</foo>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M1</version>
<executions>
<execution>
<id>require-properties</id>
<goals><goal>enforce</goal></goals>
<configuration>
<rules>
<requireProperty>
<property>${foo}</property>
<message>foo must be defined -${foo}-</message>
</requireProperty>
</rules>
<!-- Disabling, since it seems to not notice properties that are defined -->
<!-- <skip>true</skip> -->
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
When I run this, the enforcer rule fails.
$ mvn install
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------------< test:test >------------------------------
[INFO] Building test 1.0.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-enforcer-plugin:3.0.0-M1:enforce (require-properties) # test ---
[WARNING] Rule 0: org.apache.maven.plugins.enforcer.RequireProperty failed with message:
foo must be defined -bar-
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.398 s
[INFO] Finished at: 2019-03-15T11:45:58-04:00
[INFO] ------------------------------------------------------------------------
It also fails if I define it on the command line.
$ mvn install -Dfoo=quz
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------------< test:test >------------------------------
[INFO] Building test 1.0.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-enforcer-plugin:3.0.0-M1:enforce (require-properties) # test ---
[WARNING] Rule 0: org.apache.maven.plugins.enforcer.RequireProperty failed with message:
foo must be defined -quz-
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
Is this rule not for <properties> values? From the message, it is clear that the value is actually set.
I also tried adding <regex>.*</regex> with no effect.
How to I check that a maven property is set?
Real case details
In the example, the property is defined in the pom, so it sort of redundant to include the check. In the real case, the plugin is defined in the parent pom and the property is defined in the leaf pom. The behavior is the same in the real case.
mvn -version
Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-24T14:41:47-04:00)
Maven home: /usr/local/Cellar/maven/3.6.0/libexec
Java version: 10.0.1, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.14.3", arch: "x86_64", family: "mac"

Related

liberty:devc: <dockerfile> not being honored

I observe that the <dockerfile> element, though it points to a valid Dockerfile is not honored by liberty:devc.
Consider this output from mvn help:effective-pom:
<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>
<parent>
<groupId>javaee-cafe</groupId>
<artifactId>javaee-cafe-parent</artifactId>
<version>1.0.0</version>
<relativePath />
</parent>
<groupId>javaee-cafe</groupId>
<artifactId>javaee-cafe-jcache</artifactId>
<version>1.0.3</version>
<packaging>war</packaging>
<name>javaee-cafe-jcache</name>
<properties>
<dockerFileName>Dockerfile</dockerFileName>
<failOnMissingWebXml>false</failOnMissingWebXml>
<!-- elided -->
<usrDirectory>/home/edburns/workareas/open-liberty-on-aks/javaee-app-redisson/target/liberty/wlp/usr</usrDirectory>
</properties>
<dependencies><!-- elided --></dependencies>
<build>
<sourceDirectory>/home/edburns/workareas/open-liberty-on-aks/javaee-app-redisson/src/main/java</sourceDirectory>
<!-- elided -->
<resources>
<resource>
<filtering>true</filtering>
<directory>/home/edburns/workareas/open-liberty-on-aks/javaee-app-redisson/src/main/resources</directory>
</resource>
</resources>
<directory>/home/edburns/workareas/open-liberty-on-aks/javaee-app-redisson/target</directory>
<finalName>javaee-cafe-jcache</finalName>
<plugins>
<!-- elided -->
<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>3.3.4</version>
<executions>
<execution>
<id>package-server</id>
<phase>package</phase>
<goals>
<goal>create</goal>
<goal>install-feature</goal>
<goal>deploy</goal>
</goals>
<configuration>
<container>true</container>
<dockerfile>/home/edburns/workareas/open-liberty-on-aks/javaee-app-redisson/target/Dockerfile</dockerfile>
<libertyRuntimeVersion>[21.0.0.5,)</libertyRuntimeVersion>
<serverXmlFile>/home/edburns/workareas/open-liberty-on-aks/javaee-app-redisson/target/liberty/wlp/usr/servers/defaultServer/server.xml</serverXmlFile>
<copyDependencies><!-- elided --></copyDependencies>
<outputDirectory>/home/edburns/workareas/open-liberty-on-aks/javaee-app-redisson/target/wlp-package</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</build>
</project>
When I run mvn liberty:devc I see this output:
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------< javaee-cafe:javaee-cafe-jcache >-------------------
[INFO] Building javaee-cafe-jcache 1.0.3
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- liberty-maven-plugin:3.3.4:devc (default-cli) # javaee-cafe-jcache ---
[INFO] CWWKM2102I: Using artifact based assembly archive : io.openliberty:openliberty-kernel:null:21.0.0.5:zip.
[INFO] CWWKM2102I: Using installDirectory : /home/edburns/workareas/open-liberty-on-aks/javaee-app-redisson/target/liberty/wlp.
[INFO] CWWKM2102I: Using serverName : defaultServer.
[INFO] CWWKM2102I: Using serverDirectory : /home/edburns/workareas/open-liberty-on-aks/javaee-app-redisson/target/liberty/wlp/usr/servers/defaultServer.
<!-- elided -->
[INFO] Running liberty:deploy
[INFO] The liberty.runtime.version property value [21.0.0.5,) is used for the runtimeArtifact version.
[INFO] CWWKM2102I: Using artifact based assembly archive : io.openliberty:openliberty-kernel:null:21.0.0.5:zip.
[INFO] CWWKM2102I: Using installDirectory : /home/edburns/workareas/open-liberty-on-aks/javaee-app-redisson/target/liberty/wlp.
[INFO] CWWKM2102I: Using serverName : defaultServer.
[INFO] CWWKM2102I: Using serverDirectory : /home/edburns/workareas/open-liberty-on-aks/javaee-app-redisson/target/liberty/wlp/usr/servers/defaultServer.
[INFO] Copying 1 file to /home/edburns/workareas/open-liberty-on-aks/javaee-app-redisson/target/liberty/wlp/usr/servers/defaultServer
[WARNING] The /home/edburns/workareas/open-liberty-on-aks/javaee-app-redisson/src/main/liberty/config/server.xml file is overwritten by the /home/edburns/workareas/open-liberty-on-aks/javaee-app-redisson/target/liberty/wlp/usr/servers/defaultServer/server.xml file.
[INFO] Copying 1 file to /home/edburns/workareas/open-liberty-on-aks/javaee-app-redisson/target/liberty/wlp/usr/servers/defaultServer
[INFO] CWWKM2144I: Update server configuration file server.xml from /home/edburns/workareas/open-liberty-on-aks/javaee-app-redisson/target/liberty/wlp/usr/servers/defaultServer/server.xml.
[INFO] CWWKM2144I: Update server configuration file bootstrap.properties from inlined configuration.
<!-- elided -->
[INFO] CWWKM2185I: The liberty-maven-plugin configuration parameter "appsDirectory" value defaults to "apps".
[INFO] CWWKM2160I: Installing application javaee-cafe-jcache.war.xml.
[INFO] Parsing the server file /home/edburns/workareas/open-liberty-on-aks/javaee-app-redisson/target/liberty/wlp/usr/servers/defaultServer/server.xml for features and includes.
[INFO] Copying 1 file to /home/edburns/workareas/open-liberty-on-aks/javaee-app-redisson/target/liberty/wlp/usr/servers/defaultServer
[INFO] CWWKM2144I: Update server configuration file server.xml from /home/edburns/workareas/open-liberty-on-aks/javaee-app-redisson/src/main/liberty/config/server.xml.
[INFO] CWWKM2144I: Update server configuration file bootstrap.properties from inlined configuration.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.665 s
[INFO] Finished at: 2021-06-10T18:05:42-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.openliberty.tools:liberty-maven-plugin:3.3.4:devc (default-cli) on project javaee-cafe-jcache: No Dockerfile was found at /home/edburns/workareas/open-liberty-on-aks/javaee-app-redisson/Dockerfile. Create a Dockerfile at the specified location to use dev mode with container support. For an example of how to configure a Dockerfile, see https://github.com/OpenLiberty/ci.docker -> [Help 1]
<!-- elided -->
Compilation exited abnormally with code 1 at Thu Jun 10 18:05:42
It looks like the <dockerfile>, though it exists, is not being honored.
<dockerfile>/home/edburns/workareas/open-liberty-on-aks/javaee-app-redisson/target/Dockerfile</dockerfile>
Is this a bug?
Thanks,
Ed
SOLUTION: Use plugin-level configuration (not execution-level)
You need to add your configuration at the plugin level rather than the execution level.
So it should look more like:
<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>3.3.4</version>
<configuration>
<dockerfile>/home/edburns/workareas/open-liberty-on-aks/javaee-app-redisson/target/Dockerfile</dockerfile>
<!-- ... rest of config ... -->
</configuration>
</plugin>
The liberty:dev and liberty:devc goals kind of encapsulate a lifecycle inside a single goal, executed iteratively in a loop, but there isn't as much use for execution-level config. (Not sure this is really documented that well.)
OTHER THOUGHTS
If you look at the pom.xml in our sample guides like this one you'll see we don't even bother configuring other Liberty goals like create, deploy, etc. bound to phases like package.
We just use liberty:dev and liberty:devc to do iterative development, then when it's time to build the image, we do mvn package to let the maven-war-plugin build the war, then do the Docker build to build the WAR into the app image.
Of course you may have a reason to include this, and I'm getting off topic, but just adding some more context here.

Maven flatten plugin not working does not substitute my version property

For some reason when i do mvn install and check my local repo and look at the pom there, i don't see that the version variable was substituted with the value.
I am using a parent pom with a version in the properties
<properties>
<maven.javadoc.skip>true</maven.javadoc.skip>
<revision>19.3.29</revision>
</properties>
It also contains the flatten plugin entry:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.2.2</version>
<configuration>
<updatePomFile>true</updatePomFile>
<flattenMode>resolveCiFriendliesOnly</flattenMode>
</configuration>
<executions>
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
The child pom uses the ${revision} as the value for the version & ${project.version} for dependencies as recommended by maven:
<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>
<artifactId>analysisModule</artifactId>
<version>${revision}</version>
<parent>
<groupId>com.mycompany.analysis</groupId>
<version>1.0.0</version>
<artifactId>autoav</artifactId>
<relativePath>../autoAV</relativePath>
</parent>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<dependencies>
<dependency>
<groupId>com.mycompany.analysis</groupId>
<artifactId>analysisCore</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Looking at the local repo pom xml after I 'mvn install' :
<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>
<artifactId>analysisJdbc</artifactId>
<version>${revision}</version>
<description>analysis of jdbc sources</description>
<parent>
<groupId>com.mycompany.analysis</groupId>
<version>1.0.0</version>
<artifactId>autoav</artifactId>
<relativePath>../autoAV</relativePath>
</parent>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<dependencies>
<dependency>
<groupId>com.mycompany.analysis</groupId>
<artifactId>analysisCore</artifactId>
<version>${project.version}</version>
</dependency>
...
</project>
Shouldn't the ${revision} & ${project.version} been replaced with the actual numbers ?
Isn't that the whole thing about using flatten plugin ?
I followed this
https://www.mojohaus.org/flatten-maven-plugin/examples/example-central-version.html
Adding my output of mvn install (skipping tests) (maven version 3.3.9):
02:12:03 :/code/thedrs/gitrepos/analysis/analysis/analysisJdbc (main) $ mvn install -Dmaven.test.skip=true
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building analysisJdbc 19.3.30
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # analysisJdbc ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # analysisJdbc ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # analysisJdbc ---
[INFO] Not copying test resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # analysisJdbc ---
[INFO] Not compiling test sources
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # analysisJdbc ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # analysisJdbc ---
[INFO] Building jar: /code/thedrs/gitrepos/analysis/analysis/analysisJdbc/target/analysisJdbc-19.3.30.jar
[INFO] META-INF/maven/com.mycompany.analysis/analysisJdbc/pom.xml already added, skipping
[INFO] META-INF/maven/com.mycompany.analysis/analysisJdbc/pom.properties already added, skipping
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) # analysisJdbc ---
[INFO] Installing /code/thedrs/gitrepos/analysis/analysis/analysisJdbc/target/analysisJdbc-19.3.30.jar to /code/thedrs/.m2/com/mycompany/analysis/analysisJdbc/19.3.30/analysisJdbc-19.3.30.jar
[INFO] Installing /code/thedrs/gitrepos/analysis/analysis/analysisJdbc/pom.xml to /code/thedrs/.m2/com/mycompany/analysis/analysisJdbc/19.3.30/analysisJdbc-19.3.30.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.147 s
[INFO] Finished at: 2020-05-06T02:12:40-07:00
[INFO] Final Memory: 14M/356M
[INFO] ------------------------------------------------------------------------
You need to move the plugin from <pluginManagement><plugins> to <plugins>. Alternatively, you can leave it there and just add a short plugin definition (including groupId and artifactId) to the <plugins> section.
<pluginManagement> is just to preconfigure version numbers and configuration. Plugins in <pluginManagement> are not run during the build unless they reappear in <plugins>.
I've been able to achieve that by creating another property for the dependencies. This property will have the same value as ${revision} and will be replaced in the generated pom file.
<properties>
<revision>19.3.29</revision>
<my-lib.version>${revision}</my-lib.version>
</properties>
Then instead of using ${project.version} in your dependencies, use your property:
<dependency>
<groupId>com.mycompany.analysis</groupId>
<artifactId>analysisCore</artifactId>
<version>${my-lib.version}</version>
</dependency>

Maven ignoring plugin version from pluginManagement in profile of submodule

I'm defining plugin versions in the <pluginManagement> section of a parent POM and want to use them in the <plugins> section of submodules.
This is working, unless the plugin is being used inside a profile of a submodule. In this case, the version from the parent POM's <pluginManagement> section is ignored.
Output of mvn -v:
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T17:41:47+01:00)
Maven home: /usr/local/Cellar/maven/3.3.9/libexec
Java version: 1.8.0_102, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home/jre
Default locale: de_DE, platform encoding: UTF-8
OS name: "mac os x", version: "10.11.6", arch: "x86_64", family: "mac"
./pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<prerequisites>
<maven>3.1.0</maven>
</prerequisites>
<modules>
<module>project1</module>
</modules>
<groupId>org.example.test</groupId>
<artifactId>test-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
./project1/pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<prerequisites>
<maven>3.1.0</maven>
</prerequisites>
<parent>
<groupId>org.example.test</groupId>
<artifactId>test-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>project1</artifactId>
<profiles>
<profile>
<id>p1</id>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Output of mvn versions:display-plugin-updates:
$ mvn versions:display-plugin-updates
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] test-parent
[INFO] project1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building test-parent 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.2:display-plugin-updates (default-cli) # test-parent ---
[INFO]
[INFO] All plugins with a version specified are using the latest versions.
[INFO]
[INFO] Project defines minimum Maven version as: 3.1.0
[INFO] Plugins require minimum Maven version of: 3.1.0
[INFO] Note: the super-pom from Maven 3.3.9 defines some of the plugin
[INFO] versions and may be influencing the plugins required minimum Maven
[INFO] version.
[INFO]
[INFO] No plugins require a newer version of Maven than specified by the pom.
[INFO]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building project1 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.2:display-plugin-updates (default-cli) # project1 ---
[INFO]
[INFO] All plugins with a version specified are using the latest versions.
[INFO]
[WARNING] The following plugins do not have their version specified:
[WARNING] com.github.eirslett:frontend-maven-plugin ................. 0.0.26
[INFO]
[INFO] Project defines minimum Maven version as: 3.1.0
[INFO] Plugins require minimum Maven version of: 3.1.0
[INFO] Note: the super-pom from Maven 3.3.9 defines some of the plugin
[INFO] versions and may be influencing the plugins required minimum Maven
[INFO] version.
[INFO]
[INFO] No plugins require a newer version of Maven than specified by the pom.
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] test-parent ........................................ SUCCESS [ 0.851 s]
[INFO] project1 ........................................... SUCCESS [ 0.314 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.649 s
[INFO] Finished at: 2016-09-16T16:03:04+02:00
[INFO] Final Memory: 13M/247M
[INFO] ------------------------------------------------------------------------
I can duplicate the information from the <pluginManagement> section of the parent POM inside the submodules to make it work, but I want to avoid this for obvious reasons.
Maven is not ignoring it, you can check it by executing the following:
mvn -pl project1 help:effective-pom -Doutput=noProfilePom.xml
The effective-pom goal will:
Displays the effective POM as an XML for this build, with the active profiles factored in.
Checking the noProfilePom.xml generated, you will see what effectively Maven will run when building the pom.xml of the project1 module.
There we can see:
<pluginManagement>
<plugins>
...
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.0</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
...
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>default-clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
Hence, the pluginManagement has been merged properly (taken from the parent), while the plugins section doesn't provide it.
But running the following:
mvn -pl project1 -Pp1 help:effective-pom -Doutput=withProfilePom.xml
Note: we are also activating the profile via -Pp1 as part of the goal execution.
As part of the generated withProfilePom.xml will have:
<pluginManagement>
<plugins>
...
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.0</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.0</version>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>default-clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
This time the p1 profile was active and its has properly injected into the plugins section its plugin declaration, taking then its version from the pluginManagement of the parent.
Hence: the pluginManagement section is not ignored by plugins declared in a profile.

Maven build not finding custom jar already installed in local openshift project repo

I am facing an issue when trying to build my project (from the Eclipse Openshift plugin).
1.) I have a custom dependency, which at first I followed instructions on Open Shift Knowledgebase Article "Using your own jar files..."
2.) On commit and publish with above, the error still persisted, thereby I changed the openshift pre_build action hook as noted in this post on the Openshift forums "Resolved custom jar dependency..."
However, I am still getting an error on commit and publish from eclipse. Here's a dump from the console
Repository ssh://53211e7...50000f0#testapp0...312-systix.rhcloud.com/~/git/testapp0...312.git/
Stopping RockMongo cartridge
[Sun Mar 16 12:20:37 2014] [warn] module php5_module is already loaded, skipping
httpd (no pid file) not running
MongoDB already stopped
Stopping jbossas cartridge
Repairing links for 1 deployments
Building git ref 'master', commit bb2def3
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install-file (default-cli) # standalone-pom ---
[INFO] Installing /var/lib/openshift/app-root/runtime/repo/shared-helper-data-skychart-0.0.1-SNAPSHOT.jar to /var/lib/openshift/53211e...0f0/.m2/repository/com/systix/shared-helper-data-skychart/0.0.1-SNAPSHOT/shared-helper-data-skychart-0.0.1-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.331s
[INFO] Finished at: Sun Mar 16 12:20:48 EDT 2014
[INFO] Final Memory: 4M/78M
[INFO] ------------------------------------------------------------------------
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install-file (default-cli) # standalone-pom ---
[INFO] Installing /var/lib/openshift/app-root/runtime/repo/shared-models-skychart-0.0.1-SNAPSHOT.jar to /var/lib/openshift/5321......00f0/.m2/repository/com/systix/shared-models-skychart/0.0.1-SNAPSHOT/shared-models-skychart-0.0.1-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.723s
[INFO] Finished at: Sun Mar 16 12:20:53 EDT 2014
[INFO] Final Memory: 4M/78M
[INFO] ------------------------------------------------------------------------
Found pom.xml... attempting to build with 'mvn -e clean package -Popenshift -DskipTests'
Apache Maven 3.0.3 (r1075437; 2011-06-20 13:22:37-0400)
Maven home: /etc/alternatives/maven-3.0
Java version: 1.7.0_51, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.51/jre
Default locale: en_US, platform encoding: ANSI_X3.4-1968
OS name: "linux", version: "2.6.32-431.5.1.el6oso.bz844450.x86_64", arch: "i386", family: "unix"
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building testapp0...312 1.0
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.134s
[INFO] Finished at: Sun Mar 16 12:21:04 EDT 2014
[INFO] Final Memory: 5M/111M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project testapp0...0312: Could not resolve dependencies for project testapp0...0312:testapp0...312:war:1.0: Could not find artifact com.systix:shared-helper-data-skychart:jar:0.0.1-SNAPSHOT -> [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/DependencyResolutionException
An error occurred executing 'gear postreceive' (exit code: 1)
Error message: CLIENT_ERROR: Failed to execute: 'control build' for /var/lib/openshift/5321...00f0/jbossas
For more details about the problem, try running the command again with the '--trace' option.
On reviewing the above it seems like maven is able to add the dependency jars succesfully to the local repo ,but the build for the project does not seem to.
UPDATE: Including the pom.xml from both the libraries that I have marked as to be installed in the pre_build file. Both the jars were built, included in the openshift git repo, and referenced in the pre_build script to be installed in openshift's maven repo (pre_build script included at end)
pom.xml from shared-helper-data-skychart:
<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.systix</groupId>
<artifactId>shared-helper-data-skychart</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>2.11.4</version>
</dependency>
<dependency>
<groupId>com.systix</groupId>
<artifactId>shared-models-skychart</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.mongodb.morphia</groupId>
<artifactId>morphia</artifactId>
<version>0.105</version>
</dependency>
</dependencies>
</project>
pom.xml from shared-models-skychart (shared-models-skychart is a dependency in the pom.xml for shared-helper-data-skychart)
<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.systix</groupId>
<artifactId>shared-models-skychart</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.mongodb.morphia</groupId>
<artifactId>morphia</artifactId>
<version>0.105</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.7.3</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>2.11.4</version>
</dependency>
</dependencies>
</project>
pre_build script used
mvn install:install-file -Dfile=../app-root/runtime/repo/shared-helper-data-skychart-0.0.1-SNAPSHOT.jar -DgroupId=com.systix -DartifactId=shared-helper-data-skychart -Dversion=0.0.1-SNAPSHOT -Dpackaging=jar
mvn install:install-file -Dfile=../app-root/runtime/repo/shared-models-skychart-0.0.1-SNAPSHOT.jar -DgroupId=com.systix -DartifactId=shared-models-skychart -Dversion=0.0.1-SNAPSHOT -Dpackaging=jar
UPDATE 2: Also, the above pom.xml is what I have in my project code files. However, when I ssh intoopenshift servers and review the local maven repos, the following is what I see as pom.xml
cat ./.m2/repository/com/systix/shared-helper-data-skychart/0.0.1-SNAPSHOT/shared-helper-data-skychart-0.0.1-SNAPSHOT.pom
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.systix</groupId>
<artifactId>shared-helper-data-skychart</artifactId>
<version>0.0.1-SNAPSHOT</version>
<description>POM was created from install:install-file</description>
</project>
This is what worked for me:
I connected via SSH to OpenShift like described here.
There I found out that in the OpenShift maven repo (under ~/.m2/repository/) the jar had not been installed correctly. In the dependency directory there were *.jar.lastUpdated files instead of the actual jars.
I deleted the whole directory of the problematic dependency from the maven repo (manually)
In my pre_build action hook I changed mvn install:install -Dfile path to an absolute path to the jar (e.g. /var/lib/openshift/___your__id__here____/app-root/runtime/repo/dependencyfile.jar
I pushed my local changes (pre_build action hook changed in point 4.) to the git repo. Now all worked fine :)

unable to run Maven projects from TestNG thru command line...!

i have configured my eclipse with maven and testNG, PF my pom.xml 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>
<parent>
<artifactId>iONAutomation</artifactId>
<groupId>com.iON.tcs</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.iON.tcs</groupId>
<artifactId>common</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>common</name>
<description>maintains all common code</description>
<profiles>
<profile>
<id>selenium-tests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.3.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
am runnong from the cmd prompt thu this dir: D:\EclipseWorkspace\iON27Feb2013\iONAutomation\common>
I tried usinng mvn test and mvn -Dtest=NewTest test commands, didnot succeed.
My cmd console displays:
D:\EclipseWorkspace\iON27Feb2013\iONAutomation\common>mvn test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building common 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) # common ---
[debug] execute contextualize
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) # common ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) # co
mmon ---
[debug] execute contextualize
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) # commo
n ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.10:test (default-test) # common ---
[INFO] Surefire report directory: D:\EclipseWorkspace\iON27Feb2013\iONAutomation
\common\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.932s
[INFO] Finished at: Thu Feb 28 19:11:43 IST 2013
[INFO] Final Memory: 4M/15M
[INFO] ------------------------------------------------------------------------
If you have a profile defined, then afaik, you need to invoke that profile ...mvn test -Pselenium-tests. As such if there is no particular reason for u to use profiles, then you might just go without them, in which case mvn test should work just fine.
Did you try to put
<sourceDirectory>/home/{userName}/{projectLocation}/src/main/java/packageTest</sourceDirectory>
inside your build ?
I had the same problem and this line solved it.
You can also try to add a goal to your pom file
<execution>
<id>default-test</id>
<phase>test</phase>``
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
</configuration>
</execution>
Hope it will help you !

Resources