How to pass external groovy script in pom.xml (Soapui and Maven Integration) - maven

my pom.xml is here with project.xml and soapui-setting.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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com</groupId>
<artifactId>SOAPUI</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>SOAPUI</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>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0</version>
</dependency>
</dependencies>
<pluginRepositories>
<pluginRepository>
<id>smartbear-sweden-plugin-repository</id>
<url>http://www.soapui.org/repository/maven2/</url>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>com.smartbear.soapui</groupId>
<artifactId>soapui-pro-maven-plugin</artifactId>
<version>4.6.2</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<projectFile>SOAPUI-soapui-project.xml</projectFile>
<junitReport>true</junitReport>
<outputFolder>reports\</outputFolder>
<testSuite>UVConnect_Users</testSuite>
<testCase>TC_DECE_00001_UV_UserCreate_Adult_FAU_TOU_NotAccepted</testCase>
<settingsFile>C:\Users\omkar.khatavkar\soapui-settings.xml</settingsFile>
<soapuiProperties>
<property>
<name>soapui.scripting.library</name>
<value>C:\Scripts</value>
</property>
</soapuiProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
but after giving mvn test as maven target then it gives failure as it does not understand.
Is there any way I can pass external written groovy scripts into Soap ui Maven command line target ?
00:25:00,371 ERROR [SoapUI] An error occurred [startup failed:
Script1.groovy: 15: unable to resolve class dbUtils.dbUtils
# line 15, column 9.
def a = new dbUtils.dbUtils(log,dBHost);
^`enter code here`

... after giving mvn test ...
That should be: mvn com.smartbear.soapui:soapui-maven-plugin:test, right?
Is there any way I can pass external written groovy scripts into Soap ui Maven command line target ?
There are two options:
If you have the -Pro version (which from your pom seems like you do not), you can use the Script Library. Be careful how you specify the path, so that it works on your CI machine!
Compile the scripts to a jar and specify it as a dependency in the soapui-maven-plugin in your pom.
You might need to read through the SoapUI docs.

I added path for Script and Ext folder which i was missing. here is my updated 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com</groupId>
<artifactId>SOAPUI</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>SOAPUI</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<pluginRepositories>
<pluginRepository>
<id>smartbear-sweden-plugin-repository</id>
<url>http://www.soapui.org/repository/maven2/</url>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>com.smartbear.soapui</groupId>
<artifactId>soapui-pro-maven-plugin</artifactId>
<version>4.6.1</version>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<projectFile>SOAPUI-soapui-project.xml</projectFile>
<junitReport>true</junitReport>
<outputFolder>reports\</outputFolder>
<testSuite>UVConnect_Users</testSuite>
<testCase>TC_DECE_00001_UV_UserCreate_Adult_FAU_TOU_NotAccepted</testCase>
<settingsFile>C:\Users\omkar.khatavkar\soapui-settings.xml</settingsFile>
<soapuiProperties>
<property>
<name>soapui.scripting.library</name>
<value>C:\Scripts</value>
</property>
<property>
<name>soapui.ext.libraries</name>
<value>C:\Program Files\SmartBear\SoapUI-Pro-4.6.1\lib</value>
</property>
</soapuiProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Related

How to resolve a conflict with a system scope dependency jar

I have a jar that my code depends on and it is located locally on my PC.
That jar contains the 'org.apache.commons.lang3' package but an older version or a version that contains the class 'StringUtils' but without all of its methods.
In my maven pom, I am using the 'org.apache.commons.lang3' dependency also but at runtime I get the error 'NoSuchMethodError' which means that during runtime it is using the commons.lang3 version of the jar and not the one from my dependency.
Is there a way to force it to use the dependency in my pom file?
Here is how my pom looks like:
<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>test</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<test.path>C:/Users/user/test</test.path>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>dep</groupId>
<artifactId>dep</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${test.path}/dep.jar</systemPath>
</dependency>
</dependencies>
<!-- build fat jar file with dependencies -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>dep-included</shadedClassifierName>
<outputDirectory>${test.path}/out</outputDirectory>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
CONCLUSION FROM COMMENTS:
It is not possible to remove such packages in a jar with Maven. I have to manualy edit and remove the packages from the jar file.
Thank you all for taking the time to answer!

Jenkins stop build on unit test first failure

I have a maven job running in jenkins. This maven project runs soap project which contains testcases. The pom.xml of this maven project is configured as
<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>src.main.resources</groupId>
<artifactId>soapui-maven2-plugin</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>Maven 2 soapUI Sample</name>
<url>http://maven.apache.org</url>
<pluginRepositories>
<pluginRepository>
<id>smartbear-sweden-plugin-repository</id>
<url>http://www.soapui.org/repository/maven2/</url>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>com.github.redfish4ktc.soapui</groupId>
<artifactId>maven-soapui-extension-plugin</artifactId>
<version>4.6.4.2</version>
<configuration>
<runnerType>OSS</runnerType>
<projectFile>Dev-Offline-soapui-project.xml</projectFile>
<junitReport>true</junitReport>
<outputFolder>${project.build.directory}/tatunka-reports</outputFolder>
<testSuite>SmokeTestSuite</testSuite>
<testSuiteProperties>
<properties>
<property>serviceEndpoint=${serviceEndpoint}</property>
</properties>
</testSuiteProperties>
<skipAfterFailureCount>1</skipAfterFailureCount>
</configuration>
<executions>
<execution>
<configuration>
<junitReport>true</junitReport>
</configuration>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.smartbear.soapui</groupId>
<artifactId>soapui-maven-plugin</artifactId>
<version>5.1.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
And in jenkins goal and options is given as
test -DserviceEndpoint=http://localhost:8080/DAMService/solutionid -DskipTests=true
What I want is the jenkins to stop running other testcases if any testcase fails.
For example, i have 9 testcases and 4th testcase fails then remaining 5 testcases should not be executed.
I tried to give
<skipAfterFailureCount>1</skipAfterFailureCount>
but no result.
And even tried giving
-DskipTests=true option as build arguement.
And also tried with goal verify. But could not achieve to stop the running of testcases.
Please, let me know if any more information is needed.
Add <testFailureIgnore>true</testFailureIgnore>under plugin configuration and try

How to read values from .properties using maven plugin

How to read the properties from .properties file by using maven provided plugin, for one of my current project, I always used to set the properties in the <properties> tag of pom.xml, But here my requirement is, I will set the all properties in some .properties file for ex: dev.properties. It is having the following content inside it.
spring.package=org.springframework
spring.artifact=spring-core
spring.version=3.0.5.RELEASE
So, now I want to set the above properties into the pom.xml like the following:
<dependencies>
<dependency>
<groupId>spring.package</groupId>
<artifactId>spring.artifact</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
I gone through this link : How to read an external properties file in Maven
But it is giving the following error : Missing artifact org.springframework:spring-core:jar:spring.version
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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ram</groupId>
<artifactId>DynamicProperties</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<spring.version>spring.version</spring.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<urls>
<url>file:///D:/Hadoop_Apps/DynamicProperties/src/main/resources/dev.properties</url>
</urls>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
</project>
But spring-core-3.0.5.RELEASE jar is avail in maven repository.
Is there any other plugin in maven to do the same, or did I missed any additional config here.
Please correct if I am wrong.
Thanks.
First of all, when Maven reads your pom.xml, it'll immediately replace placeholders such as ${spring.version} with the actual value you specify as
<properties>
<spring.version>spring.version</spring.version>
</properties>
So changing the values later via a plugin is too late! Maven will not do this, however, if there's no value available at this time. Therefore you can remove these properties from pom.xml and let Maven plugin define them later in build lifecycle. This usually solves uses of properties overridden by plugins, but...
Second, there might be still another problem: Maven will likely resolve dependencies (including their versions) before even executing any plugin, which will prevent you from doing this whole thing. If that's the case, you can move your properties to a profile and activate a certain profile instead.
<properties>
<!-- default goes here, when no profile is used -->
<spring.version>3.0.4-RELEASE</spring.version>
</properties>
<profiles>
<profile>
<id>dev</id>
<properties>
<spring.version>3.0.5-RELEASE</spring.version>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<spring.version>3.0.1-RELEASE</spring.version>
</properties>
</profile>
</profiles>
Please find below the corrected 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>
<groupId>com.ram</groupId>
<artifactId>DynamicProperties</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<spring-version>spring.version</spring-version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<urls>
<url>file:///${basedir}\src\main\resources\config.properties</url>
</urls>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
The problem was in -
<spring.version>spring.version</spring.version>
tag. It should have been
<spring-version>spring.version</spring-version>
inside properties tag.
BR

What dependency scope for Derby JDBC drivers in intergration scope (cayenne)

I am trying to build my pom.xml so that I can automatically create my database schema when running 'mvn install'. I'm using the "maven-cayenne-plugin" to do this. This is plugin is being called (at the integration-test phase), as I can see the output. But the mojo fails with the exception: (I used the -e and -X flag to see this).
java.lang.ClassNotFoundException: org.apache.derby.jdbc.ClientDriver
(I get the same if I try and use the EmbeddedDriver and whether or not I include 'derbyclient' or simply 'derby' as my dependency).
Here's a pom.xml that should replicate the issue.
I'm using MVN 3 on Windows.
[ Apache Maven 3.0.4 (r1232337; 2012-01-17 08:44:56+0000) ]
<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.mycompany</groupId>
<artifactId>myproject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.cayenne.plugins</groupId>
<artifactId>maven-cayenne-modeler-plugin</artifactId>
<version>3.2M1</version>
</plugin>
<plugin>
<groupId>org.apache.cayenne.plugins</groupId>
<artifactId>maven-cayenne-plugin</artifactId>
<version>3.2M1</version>
<executions>
<execution>
<id>cgen</id>
<configuration>
<superPkg>com.mycompany.model.generated</superPkg>
<map>${project.build.sourceDirectory}/../resources/datamap.map.xml</map>
<destDir>${project.build.sourceDirectory}</destDir>
</configuration>
<goals>
<goal>cgen</goal>
</goals>
</execution>
<execution>
<id>cdbgen</id>
<configuration>
<map>${project.build.sourceDirectory}/../resources/datamap.map.xml</map>
<driver>org.apache.derby.jdbc.ClientDriver</driver>
<url>jdbc:derby:memory:tracedb;create=true</url>
<username>test</username>
</configuration>
<goals>
<goal>cdbgen</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbyclient</artifactId>
<version>10.10.1.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
This also requires a valid cayenne "datamap.map.xml" file (in src/main/resources), here's one I made earlier:
<?xml version="1.0" encoding="utf-8"?>
<data-map xmlns="http://cayenne.apache.org/schema/3.0/modelMap"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://cayenne.apache.org/schema/3.0/modelMap http://cayenne.apache.org/schema/3.0/modelMap.xsd"
project-version="6">
<db-entity name="TEST">
<db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
</db-entity>
</data-map>
EDIT:
Adding more information.
The derbyclient-10.10.1.1.jar does contain the class 'org.apache.derby.jdbc.ClientDriver' (just expanded the JAR from Netbeans).
The -X flag seems to show that the CLASSPATH is correctly referencing the JAR:
[DEBUG] (f) classpathElements = [<PROJECT-PATH>\mvn\target\classes, <HOME-DIR>\.m2\repository\org\apache\derby\derbyclient\10.10.1.1\derbyclient-10.10.1.1.jar]
SOLUTION:working pom.xml (see answer and my comment):
<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.mycompany</groupId>
<artifactId>myproject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.cayenne.plugins</groupId>
<artifactId>maven-cayenne-modeler-plugin</artifactId>
<version>3.2M1</version>
</plugin>
<plugin>
<groupId>org.apache.cayenne.plugins</groupId>
<artifactId>maven-cayenne-plugin</artifactId>
<version>3.2M1</version>
<dependencies>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.10.1.1</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>cgen</id>
<configuration>
<superPkg>com.mycompany.model.generated</superPkg>
<map>${project.build.sourceDirectory}/../resources/datamap.map.xml</map>
<destDir>${project.build.sourceDirectory}</destDir>
</configuration>
<goals>
<goal>cgen</goal>
</goals>
</execution>
<execution>
<id>cdbgen</id>
<configuration>
<map>${project.build.sourceDirectory}/../resources/datamap.map.xml</map>
<driver>org.apache.derby.jdbc.EmbeddedDriver</driver>
<url>jdbc:derby:memory:tracedb;create=true</url>
<username>test</username>
</configuration>
<goals>
<goal>cdbgen</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbyclient</artifactId>
<version>10.10.1.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
To ensure that the Derby driver is available during plugin execution (vs during your code compilation), you need to add it as a dependency of the plugin itself:
<plugin>
<groupId>org.apache.cayenne.plugins</groupId>
<artifactId>maven-cayenne-plugin</artifactId>
<version>3.2M1</version>
<dependencies>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbyclient</artifactId>
<version>10.10.1.1</version>
</dependency>
</dependencies>
....
</plugin>

run findbugs through maven eclipse

how to run findbugs through eclipse with maven project. I have configured in maven as:
<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.home.app</groupId>
<artifactId>home-app</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<name>home-app</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<effort>Max</effort>
<threshold>Low</threshold>
<xmlOutput>true</xmlOutput>
</configuration>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
i want to know what are the errors/warnings reported by findbugs.
You will find the report during the usual compile package phase created in the target directory. If you like to see a more readable output you have to use the findbugs goal in the reporting block instead of the build block.
You could also just use the findbugs eclipse plugin which will give you a nice eclipse window that points you directly to all of your bugs.

Resources