Maven java junit test won't start with groovy spock tests - java

I have a problem with running groovy test with java tests. I have java test in directory /src/test/java and groovy tests in directory /src/test/groovy and maven plugin config like it:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<useFile>false</useFile>
<includes>
<include>**/*Test.java</include>
<include>**/*Spec.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.12.1</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compileTests</goal>
</goals>
</execution>
</executions>
</plugin>
But with this config only groovy spock test works without java junit tests.
What am I doing wrong?
Thanks in advance for help

I had exactly same issue and adding dependency to junit-vintage-engine, solved it, e.g.:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<useFile>false</useFile>
<includes>
<include>**/*Test.java</include>
<include>**/*Spec.java</include>
</includes>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.8.1</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.12.1</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compileTests</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>

Related

How can I get all plugins from java code including default plugins? Maven

When I build an effective model using help:effective-pom I get such plugins
<plugins>
<plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.15</version>
<configuration>
<configLocation>checkstyle.xml</configLocation>
<includeTests>true</includeTests>
<linkXRef>false</linkXRef>
</configuration>
</plugin>
<plugin>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.6</version>
</plugin>
<plugin>
<groupId>some-group-id</groupId>
<artifactId>build-express</artifactId>
<version>2.2.0</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.7.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
<version>0.7</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.5.0</version>
<scope>system</scope>
<systemPath>C:\Tools\java\jdk1.8.0_74\jre/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifestEntries>
<Built-By>Apache Maven</Built-By>
</manifestEntries>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<goals>
<goal>validate</goal>
</goals>
<configuration>
<validationSets>
<validationSet>
<dir>dish_common/install</dir>
<includes>
<include>**/*.xml</include>
</includes>
</validationSet>
<validationSet>
<dir>dish_common/settings</dir>
<includes>
<include>**/*.xml</include>
</includes>
</validationSet>
</validationSets>
</configuration>
</execution>
</executions>
<inherited>false</inherited>
<configuration>
<validationSets>
<validationSet>
<dir>dish_common/install</dir>
<includes>
<include>**/*.xml</include>
</includes>
</validationSet>
<validationSet>
<dir>dish_common/settings</dir>
<includes>
<include>**/*.xml</include>
</includes>
</validationSet>
</validationSets>
</configuration>
</plugin>
<plugin>
<groupId>some-group-id</groupId>
<artifactId>some-our-plugin</artifactId>
<version>3.7.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>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>default-install</id>
<phase>install</phase>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
<executions>
<execution>
<id>default-site</id>
<phase>site</phase>
<goals>
<goal>site</goal>
</goals>
<configuration>
<outputDirectory>C:\Workspace\Projects\Dish\target\site</outputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</execution>
<execution>
<id>default-deploy</id>
<phase>site-deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<outputDirectory>C:\Workspace\Projects\Dish\target\site</outputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</execution>
</executions>
<configuration>
<outputDirectory>C:\Workspace\Projects\Dish\target\site</outputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</plugin>
</plugins>
</build>
(replaced GAV of our plugins with an abbreviation)
But when I get effective model from java code I'm not getting the last 4 plugins.
Java code
ModelBuilder modelBuilder = new DefaultModelBuilderFactory().newInstance();
ModelResolver modelResolver = ModelResolverFactory.create(aetherArtifactResolver, remoteRepositoryManager, mavenProject);
DefaultModelBuildingRequest modulebr = new DefaultModelBuildingRequest();
modulebr.setPomFile(projectPom);
modulebr.setModelResolver(modelResolver);
// modulebr.setTwoPhaseBuilding(false);
// modulebr.setProcessPlugins(true); //I try to use these settings but it also not help
modulebr.setUserProperties(props);
Model modelEffectiveModel = modelBuilder.build(modelbr).getEffectiveModel();
List<Plugin> plugins = modelEffectiveModel.getBuild().getPlugins();
public static ModelResolver create(
ArtifactResolver resolver, RemoteRepositoryManager remoteRepositoryManager, MavenProject project)
throws EffectivePomBuildingException {
try {
ProjectBuildingRequest projectBuildingRequest = project.getProjectBuildingRequest();
Class c = Class.forName("org.apache.maven.repository.internal.DefaultModelResolver");
Constructor ct = c.getDeclaredConstructor(RepositorySystemSession.class
, RequestTrace.class, String.class
, ArtifactResolver.class, VersionRangeResolver.class, RemoteRepositoryManager.class
, List.class);
ct.setAccessible(true);
return (org.apache.maven.model.resolution.ModelResolver) ct.newInstance(
projectBuildingRequest.getRepositorySession()
, null, null, resolver, new DefaultVersionRangeResolver(), remoteRepositoryManager
, project.getRemoteProjectRepositories());
} catch (Exception e) {
throw new BuildingException("Error instantiating DefaultModelResolver for parsing", e);
}
Help please
Why using the getEffectiveModel() method I don't get: maven-clean-plugin, maven-install-plugin, maven-deploy-plugin, maven-site-plugin.
And how can I get all the plugins from an effective pom?
The goal was to build an effective model and download to the folder all the dependencies, plugins (including all default plugins) and their transitives (by GAV) used for assembly, so that then to assemble the project in offline mode, roughly speaking (here is a piece of the entire implementation).
When building an effective model using ModelBuilder, it was not possible to get the default plugins of the project (such as maven-install-plugin, maven-clean-plugin, and so on). The solution is to change the construction of the model using ProjectBuilder with the following settings:
ProjectBuildingRequest projectBuildingRequest = new DefaultProjectBuildingRequest(
mavenSession.getProjectBuildingRequest());
projectBuildingRequest.setLocalRepository(mavenSession.getLocalRepository());
projectBuildingRequest.setProject(null);
projectBuildingRequest.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
projectBuildingRequest.setResolveDependencies(false);
projectBuildingRequest.setUserProperties(initAndGetProperties(rootProjectPom, mavenProject));
Model modelEffectiveModel = projectBuilder.build(pomModel.getModel().getPomFile(), request)
.getProject().getModel();
List<Plugin> plugins = model.getBuild().getPlugins();
After that, it was possible to get all the plugins of the project, including the default ones

Intellij: maven clean verify: Failed to execute goal org.jasig.mojo.jspc:jspc-maven-plugin:2.0.2:compile: Failed to compile JSPS

My project POM has following plugins-
<build>
<plugins>
<plugin>
<groupId>org.jasig.mojo.jspc</groupId>
<artifactId>jspc-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<sources>
<directory>${basedir}/src/main/webapp/</directory>
<includes>
<include>**/*.jsp</include>
</includes>
</sources>
<includeInProject>false</includeInProject>
<validateXml>false</validateXml>
</configuration>
<dependencies>
<dependency>
<groupId>org.jasig.mojo.jspc</groupId>
<artifactId>jspc-compiler-tomcat8</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.5.3</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>utf8</encoding>
</configuration>
</plugin>
</plugins>
</build>
I'm using apache-maven-3.6.3 and Intellij IDE for building my project.
But when executing mvn clean verify, I get the error-
Failed to execute goal
org.jasig.mojo.jspc:jspc-maven-plugin:2.0.2:compile: Failed to compile
JSPS
It is due to in tomcat 7 by default SKIP IDENTIFIER CHECK feature is false.
Hence supply-Dorg.apache.el.parser.SKIP_IDENTIFIER_CHECK=true as an argument while maven clean installing.
Alternatively a work around is also to use org.apache.sling jspc-maven-plugin
<plugin>
<groupId>org.apache.sling</groupId>
<artifactId>jspc-maven-plugin</artifactId>
<version>2.2.2</version>
<executions>
<execution>
<id>compile-jsp</id>
<goals>
<goal>jspc</goal>
</goals>
</execution>
</executions>
</plugin>

Corrupt JARS in zip using maven

I have maven project that i want to package in a zip file including the jar binaries(in a folder /jars). After the packaging, I've unzipped and extracted the jar file but get the below error when i invoke this:
PS C:\Users\kenochrome\Downloads> jar xf service-0.1.jar
java.util.zip.ZipException: invalid literal/length code
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:139)
at java.util.zip.ZipInputStream.read(ZipInputStream.java:142)
at sun.tools.jar.Main.extractFile(Main.java:715)
at sun.tools.jar.Main.extract(Main.java:678)
at sun.tools.jar.Main.run(Main.java:191)
at sun.tools.jar.Main.main(Main.java:904)
Below is a snippet of parent and child poms.
Parent POM
<build>
<finalName>release_1.0</finalName>
<resources>
<resource>
<directory>${basedir}/hello/world/00006/jars</directory>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.7</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptor>assembly/bin.xml</descriptor>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Child POM
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>jar</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>scala-compile</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<finalName>service-${project.version}</finalName>
<outputDirectory>../../jars</outputDirectory>
<resources>
<resource>
<directory>jars</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
</dependencies>
</project>
I'm sorry if the information is not adequate or if this question is not correctly formatted.
Many thanks for going through this post and much appreciated in advance.
Was looking through another forum and found out that the issue that I was having was using the <lineEnding>unix</lineEnding> element in my descriptor assembly xml.

Is there a way to fork Java VMs with Maven Failsafe plugin. I am using Junit with Serenity Runner

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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.idexx</groupId>
<artifactId>qe-lynxx-automation</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<serenity.version>2.0.27</serenity.version>
<lean.ft.version>14.50.0</lean.ft.version>
<test.directory>${project.build.testSourceDirectory}/tests</test.directory>
<tags></tags>
</properties>
<dependencies>
I have all the required dependencies but not including here.
I am unable to run test parallelly with forkCount or methods. It works fine would the sureFire plugin but I cannot use the surefire plugin to generate serenity reports.
I have tried a combination of forkCount and parallel that didn't work either.
I was able to fork multiple Java VMs using the sureFire.
I am trying to run test parallelly in multiple virtual machines. Our application is swing based java application and we are using LeanFt to automate the testing process.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<forkCount>2</forkCount>
<reuseForks>false</reuseForks>
<includes>
<!-- Run every java class in the 'tests' package -->
<include>${test.directory}/*.java</include>
</includes>
<systemPropertyVariables>
<tags>${tags}</tags>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.serenity-bdd.maven.plugins</groupId>
<artifactId>serenity-maven-plugin</artifactId>
<version>${serenity.version}</version>
<executions>
<execution>
<id>serenity-reports</id>
<phase>post-integration-test</phase>
<goals>
<goal>aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
I figured out how it actually works. All you have to do is add Surefire plugin with Failsafe plugin when you use both of them. It works like a charm.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<includes>
<!-- Run every java class in the 'tests' package -->
<include>${test.directory}/*.java</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>net.serenity-bdd.maven.plugins</groupId>
<artifactId>serenity-maven-plugin</artifactId>
<version>${serenity.maven.version}</version>
<configuration>
<tags>${tags}</tags>
</configuration>
<executions>
<execution>
<id>serenity-reports</id>enter code here
<phase>post-integration-test</phase>
<goals>
<goal>aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Include dependency in maven shade plugin

I am trying to create a deploy-able jar which using Apache's commons-lang3. However my AWS cluster where my Hadoop is does not contain this library so I get a classNotFoundException. I figured I needed to manually add that dependency in but I am having issues working with the maven shade plugin (I was recommended to use this) My current pom file looks like this :
<dependency>
<groupId>org.apache.pig</groupId>
<artifactId>pig</artifactId>
<version>0.12.0-cdh5.2.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifact>org.apache.commons:commons-lang3</artifact>
<includes>
<include>org/apache/commons/commons-lang3/3.4/*</include>
</includes>
<minimizeJar>true</minimizeJar>
</configuration>
</execution>
</executions>
</plugin>
I want a completely normal jar with the addition of the commons-lang3 library embedded inside. Is there something I am doing incorrectly?
To include whitelisted jars you need to do the following:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>org.apache.commons:commons-lang3</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Categories

Resources