gmaven plugin: how to set property in pom.xml for external groovy script - maven

I'm running an external groovy script via gmaven plugin in pom.xml.
The external script is say 'myscript.groovy'.
I want to provide some parameters/arguments to myscript.groovy via the maven pom.xml [i.e. inside the plugin 'gmaven-plugin' execution]; but unable to do so..
I've tried using in ; but not sure how to retrieve its values in the groovy script. Simply calling properties.get is not giving the property value.
Snap of pom file:
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<id>generate-resources-execute-groovyscript</id>
<phase>generate-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<properties>
<property>
<name>installation.dir</name>
<value>${installation.dir}</value>
</property>
</properties>
<source>${pom.basedir}/src/main/groovy/configure.groovy</source>
</configuration>
</execution>
</executions>
</plugin>
Not sure how to retrieve the value of 'installation.dir' property in 'configure.groovy' script.
Any hint in this regard will be useful.. thanks

There are two ways you can bind and retrieve properties. One would be through plugin-specific properties.
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<id>generate-resources-execute-groovyscript</id>
<phase>generate-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<properties>
<installation.dir>${installation.dir}</installation.dir>
</properties>
<source>${pom.basedir}/src/main/groovy/configure.groovy</source>
</configuration>
</execution>
</executions>
</plugin>
These would be retrieved in the script like project.properties['installation.dir'].
GMaven isn't maintained anymore (I was the last maintainer). If you want to use versions of Groovy newer than 2.0.0, have a look at GMavenPlus. Here's the equivalent POM:
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>execute</goal>
</goals>
<phase>generate-resources</phase>
</execution>
</executions>
<configuration>
<bindPropertiesToSeparateVariables>false</bindPropertiesToSeparateVariables>
<properties>
<property>
<name>installation.dir</name>
<value>${installation.dir}</value>
</property>
</properties>
<scripts>
<script>file:///${pom.basedir}/src/main/groovy/configure.groovy</script>
</scripts>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.3</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
Retrieval in this case would be like properties['installation.dir']. I know the file:/// is annoying. I've removed the requirement for that in the next release.
For GMaven or GMavenPlus, if you choose the plugin properties approach, you will need to set the value elsewhere either with something like this in your project POM
<properties>
<installation.dir>C:\someDir</installation.dir>
</properties>
Or include it in your call like mvn -Dinstallation.dir=C:\someDir
The other option is to bind to project level properties directly. You would put it in your project level properties or in your call, like mentioned above, and don't include <properties> in the plugin <configuration>. If you go this route, you'd access in your script by project.properties['installation.dir'] for either GMaven or GMavenPlus (also take out <bindPropertiesToSeparateVariables> for GMavenPlus in this case).
If this doesn't work for you, try renaming installation.dir to something like installationDir. I can't remember offhand if periods were problematic.

Related

Liquibase Parameters not being read correctly in changelog

I am attempting to get some parameters from liquibase.properties read into my changelog file but not having much success.
I am basing my work on the following stack overflow question: Liquibase changelog parameters in liquibase.properties
The following is my liquibase.properties file:
driver:com.mysql.jdbc.Driver
changeLogFile:src/main/resources/changelog/db.changelog-master.xml
url:jdbc:mysql://localhost:3306/localDB
username:root
password:superSecretPassword
verbose:true
parameter.schemaName:dev_tableName
I have a few different liquibase.properties files for different profiles on maven. The following is in my changelog file and the part I am having difficulty with.
<property name="schema" value='${schemaName}' />
The problem is the property is always coming back as the literal value "${schemaName}" and not "dev_tableName". The reason I need this is because there is a reference to another schema in my changelog that changes from environment to environment.
For example dev_tableName and sys_tableName, and I would rather have several liquibase.properties files for each environment as opposed to a full set of changelogs for each environment. Any help would be appreciated, thanks.
Edit:
If it matters- I am building this via Maven with the following settings:
<build>
<plugins>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>${liquibase-version}</version>
<configuration>
<propertyFile>${liquibase.properties.path}</propertyFile>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>update</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/java/</outputDirectory>
<processor>com.querydsl.apt.hibernate.HibernateAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<liquibase.properties.path>${project.basedir}/src/main/resources/dev/liquibase.properties</liquibase.properties.path>
<env>dev</env>
<versionNumber>${env}-${project.version}</versionNumber>
</properties>
</profile>
For anyone else having the same problem I ended up solving this issue by using Maven resource plugin instead. Link can be found here: https://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html

Soapui maven plugin ssl host parameter

We have a set of soapui tests that are being run via a maven project using the soapui maven plugin which is run by a Jenkins job as well.
As we have various environments we pass a "host" parameter via the environment, from Jenkins to the Maven build.
There is a <host>${HOST}</host> element that allows us to configure the host. The problem is that the maven plugin seems to dislike when adding the protocol prefix inside the parameter value:
<host>example.com</host> Will work
<host>https://example.com</host> Won't work (java.net.UnknownHostException: https)
So if I am not allowed to provide the protocol prefix, then I don't know how to tell the maven soapui plugin that the host is using ssl.
Here is the configuration in the pom.xml that we are using:
<build>
<plugins>
<plugin>
<groupId>com.smartbear.soapui</groupId>
<artifactId>soapui-pro-maven-plugin</artifactId>
<version>5.0.0</version>
<dependencies>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</dependency>
</dependencies>
<configuration>
<projectFile>${project.build.directory}/test-classes/my-soapui-project.xml</projectFile>
<host>${HOST}</host>
<junitReport>true</junitReport>
<soapuiProperties>
<property>
<name>soapui.logroot</name>
<value>${project.build.directory}/soapui-logs/</value>
</property>
</soapuiProperties>
<outputFolder>${project.build.directory}/soapui-output</outputFolder>
</configuration>
<executions>
<execution>
<id>first-tests</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<testSuite>first-TestSuite</testSuite>
</configuration>
</execution>
<execution>
<id>second-tests</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<testSuite>second-TestSuite</testSuite>
</configuration>
</execution>
</executions>
</plugin>
...
Edited: Based in the answer by Bistro:
Instead of using <host>${HOST}</host> I now use <endpoint>${HOST}</endpoint> it does the trick.
Can you try adding an <endpoint> parameter. Someone in the SoapUI forum had a similar issue, but was able to resolve the connection issue by adding this parameter. He does mention that it causes another issue. But it's worth a shot. Here is the post link

Use dependency command line parameters with maven build

I am using findbugs-maven-plugin in the verify phase of the maven life cycle. i.e. it runs on mvn clean install. This is the code I have in my parent pom.xml (in a multi-module project).
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>findbugs</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<findbugsXmlOutputDirectory>target/findbugs</findbugsXmlOutputDirectory>
<failOnError>false</failOnError>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>transform</goal>
</goals>
</execution>
</executions>
<configuration>
<transformationSets>
<transformationSet>
<dir>target/findbugs</dir>
<outputDir>target/findbugs</outputDir>
<stylesheet>plain.xsl</stylesheet>
<fileMappers>
<fileMapper implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
<targetExtension>.html</targetExtension>
</fileMapper>
</fileMappers>
</transformationSet>
</transformationSets>
</configuration>
<dependencies>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>findbugs</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
</plugin>
This is working fine and html files are being generated in each module target. However I want to take this a step further by being able to use parameters allowed by findbugs during the maven build (for example onlyAnalyze). I do not want to add configuration in the pom.xml.
I want the build process to remain the same unless I specify by some command that I want to analyze only one class, for example by running:
mvn clean install -Dfindbugs:onlyAnalyze=MyClass
Do you know of a way I can do this?
This is how you can call a standalone goal:
plugin-prefix:goal or groupId:artifactId:version:goal to ensure the right version.
In your case: findbugs:findbugs
With -Dkey=value you can set plugin parameters if they are exposed. http://mojo.codehaus.org/findbugs-maven-plugin/findbugs-mojo.html doesn't show that option. Just to compare: http://mojo.codehaus.org/findbugs-maven-plugin/help-mojo.html does have such options. Here it is still called Expression with ${key}, nowadays it's generated as User property with just key.
If you want onlyAnalyze to be set from commandline, either ask the mojo-team to fix that, or do the following:
<project>
<properties>
<findbugs.onlyAnalyze>false</findbugs.onlyAnalyze> <!-- default value -->
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<configuration>
<onlyAnalyze>${findbugs.onlyAnalyze}</onlyAnalyze>
</configuration>
</plugins>
</build>
</project>
Now you can call mvn findbugs:findbugs -Dfindbugs.onlyAnalyze=true

Maven pmd plugin - Exclude/Disable a rule

I'm attempting to exclude a certain rule from pmd using the maven-pmd-plugin (in a multi-module maven project).
Approach:
Using the excludeFromFailureFile
http://maven.apache.org/plugins/maven-pmd-plugin/examples/violation-exclusions.html
Ideally, I want to exclude this rule for the entire product (based on a parent package), however,to being with I tested for a particular class - even that is not working.
Environment
Java 7, Maven 3.0.3
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.1</version>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
<configuration>
<excludeFromFailureFile>exclude-pmd.properties</excludeFromFailureFile>
</configuration>
</execution>
<execution>
<goals>
<goal>cpd-check</goal>
</goals>
<!-- Added explicit execution Id to avoid the below problem -->
<!-- 'build.pluginManagement.plugins.plugin[org.apache.maven.plugins:maven-pmd-plugin].executions.execution.id' must be unique but found duplicate execution with id default # line 1423, column 36 -->
<id>cpd-check</id>
</execution>
</executions>
Contents of exclude-pmd.properties
mycompany.project.classA=UselessParentheses
The simplest way to exclude rules, is providing your own ruleset file. You can see where to find the default ruleset file in the answer to this question. If you are using Sonar, you can retrieve the file using the permalink.
Copy the file to your parent module, and then you can customize it, deleting the rules you want to exclude, and use the following configuration:
in the parent pom.xml:
...
<properties>
<main.basedir>${project.basedir}</main.basedir>
<!-- Some child module could set this to true to skip PMD check -->
<skip.pmd.check>false</skip.pmd.check>
</properties>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<!-- This is the version I'm using -->
<version>2.7.1</version>
<configuration>
<rulesets>
<ruleset>${main.basedir}/path/to/pmd-rules.xml</ruleset>
</rulesets>
<skip>${skip.pmd.check}</skip>
</configuration>
<executions>
<execution>
<id>pmd-config</id>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
in child modules pom.xml:
<properties>
<main.basedir>${project.parent.basedir}</main.basedir>
</properties>
in some module you want to skip (i.e contains generated code):
<properties>
<main.basedir>${project.parent.basedir}</main.basedir>
<skip.pmd.check>true</skip.pmd.check>
</properties>
Hope this help!

maven 3 surefire and maven gwt exclude / include problems

I have a root pom configured with the maven-surefire-plugin and a gwt module pom configured with the gwt-maven-plugin.
After upgrading to Maven 3 I get strange errors.
The project is similar configured like described here: Separate GwtTest tests from standard unit tests
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.6</version>
<configuration>
<useSystemClassLoader>true</useSystemClassLoader>
<useManifestOnlyJar>false</useManifestOnlyJar>
<forkMode>always</forkMode>
<properties>
<property>
<name>usedefaultlisteners</name>
<value>false</value>
</property>
<property>
<name>listener</name>
<value>org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter</value>
</property>
</properties>
<argLine>-server -Xmx8192m -XX:MaxPermSize=1024M -XX:+CMSClassUnloadingEnabled</argLine>
<excludes>
<exclude>**/*GwtTest*.java</exclude>
</excludes>
</configuration>
</plugin>
AND
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.5.0</version>
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwt.version}</version>
</dependency>
</dependencies>
<configuration>
<modules>
<module>my.app.gwt</module>
</modules>
<runTarget>/</runTarget>
<extraJvmArgs>-Xss512m -Xmx2048m -XX:MaxPermSize=256M</extraJvmArgs>
<hostedWebapp>${project.build.directory}/${project.build.finalName}</hostedWebapp>
<includes>**/*GwtTestSuite.java</includes>
<copyWebapp>true</copyWebapp>
<logLevel>INFO</logLevel>
<persistentunitcache>false</persistentunitcache>
<draftCompile>${gwt.draftCompile}</draftCompile>
<deploy>${project.build.directory}/${project.build.finalName}/WEB-INF/deploy</deploy>
<disableCastChecking>true</disableCastChecking>
<mode>htmlunit</mode>
<skipTests>${skipGwtTests}</skipTests></configuration>
<executions>
<execution>
<id>gwt-compile</id>
<goals>
<goal>compile</goal>
</goals>
<phase>compile</phase>
</execution>
<execution>
<id>gwt-test</id>
<goals>
<goal>compile</goal>
<goal>test</goal>
</goals>
<phase>test</phase>
</execution>
</executions>
</plugin>
It works with maven 2 but with maven 3 I get :
[ERROR] Failed to execute goal org.codehaus.mojo:gwt-maven-plugin:2.5.0:test (gwt-test) on project my-webapp: Unable to parse configuration of mojo org.codehaus.mojo:gwt-maven-plugin:2.5.0:test: When configuring a basic element the configuration cannot contain any child elements. Configuration element 'excludes'. -> [Help 1]
It seems that the gwt plugin can't parse the hierarchical style of the surefire plugin.
It only compiles if I set all excludes/includes inside the gwt plugin as one comma separated string line, but that doesn't work for me, because I need to exclude the gwt tests globally, and include them locally.
The include/exclude sections get merged however, so that the two incompatible syntax definitions won't work together.
I hope somebody can give me a hint.
You can run your GWTTestCases using straight Maven Surefire, see this link.

Resources