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.
Related
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>
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"
When I try to build the project using
mvn clean package -P dev, it activates the dev profile and performs the build. But when I try with mvn clean install -P dev, it builds all the profiles.
I have more than one profiles in my pom.xml.
<profiles>
<!-- The Configuration of the development profile -->
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<build.profile.id>dev</build.profile.id>
<skip.integration.tests>true</skip.integration.tests>
<skip.unit.tests>false</skip.unit.tests>
</properties>
</profile>
<!-- The Configuration of the integration-test profile -->
<profile>
<id>integration-test</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<build.profile.id>integration-test</build.profile.id>
<skip.integration.tests>false</skip.integration.tests>
<skip.unit.tests>true</skip.unit.tests>
</properties>
</profile>
</profiles>
Also tried with mvn clean install --activate-profiles=dev, but with same results. Even -D option also did not work.
========================Update=====================================
Please find the complete POM here:
<?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>
<groupId>com.myservice</groupId>
<artifactId>myservicename</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<!-- Below property indicates the pattern of the test suite -->
<runSuite>**/*Test.class</runSuite>
</properties>
<profiles>
<!-- The Configuration of the development profile -->
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<build.profile.id>dev</build.profile.id>
<skip.integration.tests>true</skip.integration.tests>
<skip.unit.tests>false</skip.unit.tests>
</properties>
</profile>
<!-- The Configuration of the integration-test profile -->
<profile>
<id>integration-test</id>
<properties>
<build.profile.id>integration-test</build.profile.id>
<skip.integration.tests>false</skip.integration.tests>
<skip.unit.tests>true</skip.unit.tests>
</properties>
</profile>
</profiles>
<dependencies>
<!-- All Dependencies -->
</dependencies>
<build>
<plugins>
<!-- Adds source and resource directories to build -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.10</version>
<executions>
<!-- Add a new source directory to our build -->
<execution>
<id>add-integration-test-sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<!-- Configures the source directory of our integration tests -->
<sources>
<source>src/integration-test/java</source>
</sources>
</configuration>
</execution>
<!-- Add a new resource directory to our build -->
<execution>
<id>add-integration-test-resources</id>
<phase>generate-test-resources</phase>
<goals>
<goal>add-test-resource</goal>
</goals>
<configuration>
<!-- Configures the resource directory of our integration tests -->
<resources>
<!-- Placeholders that are found from the files located in the configured
resource directories are replaced with the property values found from the
profile specific configuration file. -->
<resource>
<filtering>true</filtering>
<directory>src/integration-test/resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<!-- Below plugin ensures the execution of test cases during maven build -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- Skips unit tests if the value of skip.unit.tests property is true -->
<skipTests>${skip.unit.tests}</skipTests>
<includes>
<include>${runSuite}</include>
</includes>
<excludes>
<exclude>com.myservice.testsuite.service.*</exclude>
</excludes>
</configuration>
</plugin>
<!-- Runs integration tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18</version>
<executions>
<!-- Invokes both the integration-test and the verify goals of the Failsafe Maven plugin -->
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<!-- Skips integration tests if the value of skip.integration.tests property is true -->
<skipTests>${skip.integration.tests}</skipTests>
<includes>
<include>**/*IntegrationTest.class</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</pluginManagement>
</build>
</project>
And also the console output for mvn clean install -P dev:
c:\path\to\gitrepo\service>mvn clean install -P dev
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building TwelveFactorAnswers 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.6.1:clean (default-clean) # myservicename ---
[INFO] Deleting c:\path\to\gitrepo\service\target
[INFO]
[INFO] --- jacoco-maven-plugin:0.7.9:prepare-agent (jacoco-initialize) # myservicename ---
[INFO]
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # myservicename ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # myservicename ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 16 source files to c:\path\to\gitrepo\service\target\classes
[INFO]
[INFO] --- build-helper-maven-plugin:1.10:add-test-source (add-integration-test-sources) # myservicename ---
[INFO] Test Source directory: c:\path\to\gitrepo\service\src\integration-test\java added.
[INFO]
[INFO] --- build-helper-maven-plugin:1.10:add-test-resource (add-integration-test-resources) # myservicename ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # myservicename ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory c:\path\to\gitrepo\service\src\test\resources
[INFO] Copying 3 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # myservicename ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 4 source files to c:\path\to\gitrepo\service\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) # myservicename ---
[INFO] Surefire report directory: c:\path\to\gitrepo\service\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
||
||
|| All the JUnit Test runs - sample Junit Test Class - <ServiceName>Test.java
||
||
Results :
Tests run: 5, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- jacoco-maven-plugin:0.7.9:check (jacoco-check) # myservicename ---
[INFO] Loading execution data file c:\path\to\gitrepo\service\target\jacoco.exec
[INFO] Analyzed bundle 'myservicename' with 16 classes
[INFO] All coverage checks have been met.
[INFO]
[INFO] --- maven-jar-plugin:2.6:jar (default-jar) # myservicename ---
[INFO] Building jar: c:\path\to\gitrepo\service\target\myservicename-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:1.5.9.RELEASE:repackage (default) # myservicename ---
[INFO]
[INFO] --- jacoco-maven-plugin:0.7.9:report (jacoco-site) # myservicename ---
[INFO] Loading execution data file c:\path\to\gitrepo\service\target\jacoco.exec
[INFO] Analyzed bundle 'TwelveFactorAnswers' with 16 classes
[INFO]
[INFO] --- maven-failsafe-plugin:2.18:integration-test (default) # myservicename ---
[INFO] Failsafe report directory: c:\path\to\gitrepo\service\target\failsafe-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
||
||
|| All the Integration Test runs - sample Integration Test Class - <ServiceName>IT.java
||
||
Tests run: 2, Failures: 1, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-failsafe-plugin:2.18:integration-test (integration-tests) # myservicename ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-failsafe-plugin:2.18:verify (default) # myservicename ---
[INFO] Failsafe report directory: c:\path\to\gitrepo\service\target\failsafe-reports
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:15 min
[INFO] Finished at: 2018-02-16T14:28:05+05:30
[INFO] Final Memory: 38M/269M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-failsafe-plugin:2.18:verify (default) on project myservicename: There are test failures.
[ERROR]
[ERROR] Please refer to c:\path\to\gitrepo\service\target\failsafe-reports for the individual test results.
[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 think I may have have found the reason for the above behavior. Reference
Before explaining my findings, let me clarify few things:
All my Integration Test class are post-fixed with IT (Example: ServiceIT.java)
All the Integration Test related files (sources & resources) are kept in a folder called integartion-tests inside src folder (example: "src/integration-tests/java" & "src/integration-tests/resources")
Now what I've learnt is:
integration-test phase is included in install, verify & deploy goals.
By default, maven considers any class name ending with -IT and inside test or integration-test folder (eventually in test-classes folder) as Integration Test Class.
Now in my support:
If you look closely in the console output I've pasted, you'll find that the integration-test is being executed twice -
Once:
[INFO] --- maven-failsafe-plugin:2.18:integration-test (default) # myservicename ---
[INFO] Failsafe report directory: c:\path\to\gitrepo\service\target\failsafe-reports
Twice:
[INFO] --- maven-failsafe-plugin:2.18:integration-test (integration-tests) # myservicename ---
[INFO] Tests are skipped.
The first time is being executed as default phase (as a part of install goal). The second time it is being skipped, since the dev profile is being activated, in which the integration-test are skipped.
Why am I so sure?
I changed the Integration Test classes from ServiceIT.java to ServiceIntegrationTest.java and updated the plugin accordingly in pom.xml.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18</version>
<executions>
<!-- Invokes both the integration-test and the verify goals of the Failsafe Maven plugin -->
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<!-- Skips integration tests if the value of skip.integration.tests property is true -->
<skipTests>${skip.integration.tests}</skipTests>
<includes>
<include>**/*IntegrationTest.class</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
Now, for maven, there is no default class for Integration Test and the integration-tests profile is not activated. Hence, maven did not find any default integration test to run. And the console output came as:
[INFO] --- maven-failsafe-plugin:2.18:integration-test (default) # twelvefactorquestion ---
[INFO]
[INFO] --- maven-failsafe-plugin:2.18:integration-test (integration-tests) # twelvefactorquestion ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-failsafe-plugin:2.18:verify (default) # twelvefactorquestion ---
[INFO] Failsafe report directory: c:\Work\12Factor\git\twelveFactorQuestion\target\failsafe-reports
[INFO]
[INFO] --- maven-failsafe-plugin:2.18:verify (integration-tests) # twelvefactorquestion ---
[INFO] Tests are skipped.
After many years of successful use of PMD with Ant, I am now trying without success to get PMD to work from within Maven.
To illustrate my problem, I have created a simple Maven system (based upon the Maven tutorial "my-app" hello world program). It differs only in the inclusion of a line of code which should trigger a PMD error using the basic ruleset:
Boolean bar = new Boolean("true");
When I run PMD from the command line, the problem in the code is revealed:
run.sh pmd -d src/main/java -f text -R rulesets/java/basic.xml -language java
maven-pmd-example/src/main/java/com/mycompany/app/App.java:11 Avoid instantiating Boolean objects; reference Boolean.TRUE or Boolean.FALSE or call Boolean.valueOf() instead.
However, when I run pmd from within Maven, the problem in the code is not revealed:
-> mvn pmd:check
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building my-app 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-pmd-plugin:2.7.1:check (default-cli) # my-app >>>
[INFO]
[INFO] --- maven-pmd-plugin:2.7.1:pmd (pmd) # my-app ---
[WARNING] Unable to locate Source XRef to link to - DISABLED
[INFO]
[INFO] <<< maven-pmd-plugin:2.7.1:check (default-cli) # my-app <<<
[INFO]
[INFO] --- maven-pmd-plugin:2.7.1:check (default-cli) # my-app ---
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.375s
[INFO] Finished at: Sun Feb 03 15:38:02 HST 2013
[INFO] Final Memory: 12M/309M
[INFO] ------------------------------------------------------------------------
Here is the 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 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.7.1</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<verbose>true</verbose>
<minimumPriority>0</minimumPriority>
<rulesets>
<ruleset>rulesets/basic.xml</ruleset>
</rulesets>
<targetJdk>1.6</targetJdk>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.3</version>
</plugin>
</plugins>
</build>
</project>
I have uploaded this example system to GitHub so you can see the entire example system (and download/play with it if you would like):
https://github.com/philipmjohnson/maven-pmd-example
It's because you have set the minimumPriority to 0, which will effectively prevent PMD from evaluating any rules at all (refer to this SO question for a discussion on priority).
Please refer to this section of the goal documentation for the PMD plugin for more information.
I'd suggest modifying the configuration to set the minimumPriority to 2 so that you can fail the build for BooleanInstantiation.
Hope this helps!
When using the maven release plugin I want to do some pre-work (via an ant tast) as part of the release build with the assurance that the same code base is used (so no commits sneak in between). I have an ant task that I want to call to do this, but I'm having the following issue:
inside my pom file:
<configuration>
<preparationGoals>antrun:run -Dtarget=${antTaskJarBuildXML} clean verify</preparationGoals>
</configuration>
where ${antTaskJarBuildXML} is:
<target><ant antfile=\"../build.xml\" target=\"iv_dependency_build\" /></target>
When I run release:perform this is the log:
...
[INFO] Not generating release POMs
[INFO] Executing goals 'antrun:run -Dtarget="<target><ant antfile=\"../build.xml\" target=\"iv_dependency_build\" /></target>" clean verify'...
[WARNING] Maven will be executed in interactive mode, but no input stream has been configured for this MavenInvoker instance.
[INFO] [INFO] Scanning for projects...
[INFO] [WARNING]
[INFO] [WARNING] Some problems were encountered while building the effective model for com.xactsites:iv:war:12.12.4.9
[INFO] [WARNING] The expression ${version} is deprecated. Please use ${project.version} instead.
[INFO] [WARNING]
[INFO] [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[INFO] [WARNING]
[INFO] [WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[INFO] [WARNING]
[INFO] [INFO]
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] Building iv 12.12.4.9
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [WARNING] The artifact javax.xml:jaxrpc:jar:1.1 has been relocated to javax.xml:jaxrpc-api:jar:1.1
[INFO] [INFO]
[INFO] [INFO] --- maven-antrun-plugin:1.7:run (default-cli) # iv ---
[INFO] [INFO] No ant target defined - SKIPPED
[INFO] [INFO]
[INFO] [INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) # iv ---
[INFO] [INFO] Deleting C:\dev\apps\iv\target
[INFO] [INFO]
...
And as shown in the log, I am told that no target is specified. I followed what I understood from the ant run documentation
Am I missing something in how to pass in the target name?
Is this the best approach?
Is it a matter of escaping that I am missing? I'm on windows and this is the actual value defined for the xml (${antTaskJarBuildXML}):
"<target><ant antfile=\"../build.xml\" target=\"iv_dependency_build\" /></target>"
EDIT
#carlspring has given some great feedback (+1 on his answer), however, due to the nature of the problem where not everything is mavenized I couldn't get this working. Maven is expecting to be in control of the whole release process, but I need to perform an ant task (which creates dependencies needed for the build in question) beforehand. I also need to be assured that this prework task and the regular build are built against the same git tag/hash. My current solution is to sequentially do the steps that the release plugin would perform as discussed here. Through this I can create a git tag then do the maven build against that same git tag. If there are any better ideas out there please contribute!
My suggestions would be for you to define a profile and have your ant-run definition in it.
The release plugin forks, meaning your command-line args will be ignored.
UPDATE:
Try this:
<?xml version="1.0" encoding="UTF-8"?>
<project ...>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<id>execute-prepare</id>
<!-- Set up your Ant stuff here -->
<goals>
<goal>prepare</goal>
</goals>
<configuration>
<!-- If you have args specific for your release, put them here: -->
<arguments>-Pant-run-release</arguments>
<releaseProfiles>ant-run-release</releaseProfiles>
<mavenExecutorId>forked-path</mavenExecutorId>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>ant-run-release</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>execute-something</id>
<!-- Set up your Ant stuff here -->
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>