Maven spring-data-mongodb showing lower version of mongodb-driver-core - spring

I have a project that uses spring-data-mongodb. I define the following dependency on my pom.xml:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
</dependency>
The version is managed by the parent project and the version I define is 3.3.7.
However when I run mvn dependency:tree on the project I get the following entry:
\- org.springframework.data:spring-data-mongodb:jar:3.3.7:compile
[INFO] +- org.springframework:spring-tx:jar:5.1.10.RELEASE:compile
[INFO] +- org.springframework:spring-context:jar:5.1.10.RELEASE:compile
[INFO] | \- org.springframework:spring-aop:jar:5.1.10.RELEASE:compile
[INFO] +- org.springframework:spring-beans:jar:5.1.10.RELEASE:compile
[INFO] +- org.springframework:spring-expression:jar:5.1.10.RELEASE:compile
[INFO] +- org.springframework.data:spring-data-commons:jar:2.1.11.RELEASE:compile
[INFO] +- org.mongodb:mongodb-driver-core:jar:3.8.2:compile
[INFO] | \- org.mongodb:bson:jar:3.8.2:compile
The problem here is that the version of mongodb-driver-core (one line before the end of the output above) is much lower than the one defined in the specific version of spring-data-mongodb.
I cannot understand why this is happening... I need to use the lates version of mongodb-driver-core but for some reason I am getting a lower version. My projects pom.xml is listed below (only thing missing is a custom dependency which I don't want to disclose)
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.11.2</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
</dependency>
<!-- Mongo dependencies -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-releasetrain</artifactId>
<version>Lovelace-SR11</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<delimiters>
<delimiter>#</delimiter>
</delimiters>
<useDefaultDelimiters>false</useDefaultDelimiters>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>${java.version}</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<revisionOnScmFailure>true</revisionOnScmFailure>
<shortRevisionLength>7</shortRevisionLength>
</configuration>
</plugin>
</plugins>
</build>
Adding portion of the parent pom.xml as well
<properties>
<java.version>11</java.version>
<jaxb.version>2.3.3</jaxb.version>
<spring-boot.version>2.1.9.RELEASE</spring-boot.version>
<spring.mongodb.version>3.3.7</spring.mongodb.version>
<spring-cloud.version>Greenwich.SR3</spring-cloud.version>
<spring-cloud-stream.version>Germantown.RELEASE</spring-cloud-stream.version>
<spring-cloud-app-starters.version>2.1.2.RELEASE</spring-cloud-app-starters.version>
</properties>
<dependencyManagement>
<dependencies>
<!-- Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>${spring.mongodb.version}</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>${jaxb.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
Any help would be appreciated.

Turns out that the spring-boot version defined in my parent pom.xml is the one that affects the spring-data-mongodb version. By raising the spring-boot version I solved the problem... thank you M. Deinum for the comment.

Related

Maven Surefire not detecting Junit5

I have a very simple Maven project that I updated here, I obtained it simplifying my real project:
GitHub repository
I need to run Surefire plugin to compile tests, so they can be used by Jacoco. I tried sooo many things, even changing/reducing the dependencies, but none worked!
I excluded the tests in maven-compiler-plugin because it said "package main.it.isp.utility does not exist". I don't know if excluding it is correct, though....
This is my pom.xml and project structure:
<?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>it.isp.batch</groupId>
<artifactId>Estrazioni-Batch</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
<!-- Dependency versions -->
<junit.jupiter.version>5.5.2</junit.jupiter.version>
<!-- Java 8 -->
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<java.version>1.8</java.version>
<!-- Encoding -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.17.2</version>
</dependency>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit5-engine</artifactId>
<version>5.0.0-ALPHA</version>
</dependency>
<!-- Jupiter API for writing tests -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.2</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>1.8.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-junit-jupiter -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>4.4.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.3.18</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-tx -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>5.3.18</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.4.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>3.2.1.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-dbcp2 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.9.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-lang/commons-lang -->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
<build>
<finalName>Estrazioni-Batch</finalName>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<resources>
<resource>
<directory>src/</directory>
<excludes>
<exclude>test/</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<outputDirectory>${basedir}/target/diraliases/BATCHROOT/Estrazioni-batch/classes</outputDirectory>
<testExcludes>
<testExclude>**/*Test*</testExclude>
</testExcludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M6</version>
<configuration>
<testFailureIgnore>false</testFailureIgnore>
<skip>false</skip> <!-- Please take care of these parameters. They will help you to spot failure
in test assertions -->
<skipTests>false</skipTests>
<testSourceDirectory>${basedir}/src/main/test/</testSourceDirectory>
<properties>
<property>
<name>surefire.testng.verbose</name>
<value>10</value>
</property>
</properties>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.2.0-M1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.8.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.maven.surefire/surefire-api -->
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-api</artifactId>
<version>3.0.0-M6</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<!-- Suggested to always use the latest, at minimun 0.8.3 -->
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!-- EXEC format is still used as an intermediate report format, but
it purpose is only internal to JaCoCo execution -->
<!-- It will not be parsed by Sonar. There will be one EXEC file for
each module of the application -->
<destFile>./jacoco-${project.artifactId}.exec</destFile>
</configuration>
</execution>
<execution>
<id>report</id>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- The purpose of REPORT goal is to convert each EXEC in evry output
format that JaCoCo is able to produce, including XML -->
<!-- The XML files are placed inside a temporary directory -->
<dataFile>./jacoco-${project.artifactId}.exec</dataFile>
<outputDirectory>./sonar-report/temp-jacoco-xml/${project.artifactId}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.coderplus.maven.plugins</groupId>
<artifactId>copy-rename-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>copy-file</id>
<phase>verify</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<!-- The purpose of this plugin is to collect all the XML files under
the temp directory in each module -->
<!-- and copy in to the right path scanned by Sonar. There will be
one XML file for each module -->
<sourceFile>./sonar-report/temp-jacoco-xml/${project.artifactId}/jacoco.xml</sourceFile>
<destinationFile>./sonar-report/jacoco-xml/jacoco-${project.artifactId}.xml</destinationFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
The most important thing is to follow conventions in Apache Maven. So do not change the configuration for source directory and the test directory that makes in 99.999% of the cases no sense.
So first remove the following configuration parts:
<finalName>Estrazioni-Batch</finalName>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
The <finalName> ..</finalName> does not make sense because your artifact is named based on your artifactId...furthermore an artifactId should be lowercase.
You have configured either Eclipse wrong or it's based on the wrong configuration.
The production code belongs to src/main/java/<packageName> and the according unit- or integration tests should be done into src/test/java/<packageName>.
For unit tests you should follow naming conventions like *Test.java what you already did. And for integration tests you should use *IT.java.
Furthermore remove the configuration for the resources:
<resources>
<resource>
<directory>src/</directory>
<excludes>
<exclude>test/</exclude>
</excludes>
</resource>
</resources>
Because in your setup you've already used src/main/resources for test using src/test/resources.
Looking into the pom file you have given there are other strange things like mixing different junit-jupiter versions/parts.
So first remove the following from your pom file:
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit5-engine</artifactId>
<version>5.0.0-ALPHA</version>
</dependency>
<!-- Jupiter API for writing tests -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.2</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>1.8.2</version>
</dependency>
The easiest way to handle that is to use the junit bom file like the following:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.8.2</version>
<scope>import</scope>
<type>pom</type>
</dependency>
..
</dependencyManagement>
Afterwards you have to define a single dependency in your pom like this:
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
...
</dependencies>
Furthermore remove the whole setup/configuration of maven-surefire-plugin and replace with the following:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M6</version>
</plugin>
The whole configuration/setup of the maven-compiler-plugin should simply look like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
</plugin>
Also remove the whole configuration/setup of jacoco-maven-plugin and replace it with this:
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.8</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
Remove the whole configuration/setup for copy-rename-maven-plugin.
Some words about usage of the dependencies:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
Why using different versions of the same artifact? Remove commons-lang:commons-lang:2.6 and continue to work with org.apache.commons:commons-lang3:3.12.0 instead.
If you like to use sonar report you should execute the sonar-maven-plugin which is described here: https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-maven/
There are full working example https://github.com/khmarbaise/example-junitjupiter
One final strong recommendation is to define the all the plugins which are used during the build (see the example)..

Spring Boot Maven - How is adding spring-mock breaking this project?

Disclaimer: I'm not a JVM expert, so I don't have a lot of experience with Maven or Spring. My apologies if there are any obvious mistakes.
I've inherited a Java+Kotlin project with a pom.xml as configured at the end of this question.
The problem I'm having is when I add a reference to spring-mock:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-mock</artifactId>
<version>2.0.8</version>
</dependency>
...I get this error:
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.apache.catalina.authenticator.AuthenticatorBase.startInternal(AuthenticatorBase.java:1321)
The following method did not exist:
javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;
The method's class, javax.servlet.ServletContext, is available from the following locations:
jar:file:/home/atrauzzi/.m2/repository/javax/servlet/servlet-api/2.3/servlet-api-2.3.jar!/javax/servlet/ServletContext.class
jar:file:/home/atrauzzi/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.35/tomcat-embed-core-9.0.35.jar!/javax/servlet/ServletContext.class
It was loaded from the following location:
file:/home/atrauzzi/.m2/repository/javax/servlet/servlet-api/2.3/servlet-api-2.3.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of javax.servlet.ServletContext
Original pom.xml without spring-mock added
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.myproject</groupId>
<artifactId>pdf-things</artifactId>
<version>0.0.1-development</version>
<name>pdf-things</name>
<description>PDF Things</description>
<properties>
<java.version>1.8</java.version>
<maven.test.skip>true</maven.test.skip>
<kotlin.version>1.3.72</kotlin.version>
<kotlin.compiler.progressive>true</kotlin.compiler.progressive>
</properties>
<repositories>
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://artifact.aspose.com/repo/</url>
</repository>
<repository>
<id>central</id>
<name>Maven Central</name>
<url>https://repo1.maven.org/maven2</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>html2pdf</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext7-core</artifactId>
<version>7.1.13</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-pdf</artifactId>
<version>19.12</version>
</dependency>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>19.1</version>
<classifier>jdk16</classifier>
</dependency>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-imaging</artifactId>
<version>17.9</version>
<classifier>jdk16</classifier>
</dependency>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-cells</artifactId>
<version>19.1</version>
</dependency>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-cells</artifactId>
<version>19.1</version>
<classifier>javadoc</classifier>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk16</artifactId>
<version>1.46</version>
</dependency>
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>7.0.1</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-blob</artifactId>
<version>12.6.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-webmvc-core</artifactId>
<version>1.3.9</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>2.1.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmTarget>1.8</jvmTarget>
<compilerPlugins>
<!-- Or "jpa" for JPA support -->
<plugin>no-arg</plugin>
</compilerPlugins>
<pluginOptions>
<option>no-arg:annotation=com.my.Annotation</option>
<!-- Call instance initializers in the synthetic constructor -->
<!-- <option>no-arg:invokeInitializers=true</option> -->
</pluginOptions>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-noarg</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>java-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>java-test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
You can use mvn dependency:tree to see all of your project's dependencies. With a dependency on spring-mock added to your project, part of that tree is the following:
[INFO] com.myproject:pdf-things:jar:0.0.1-development
[INFO] +- org.springframework:spring-mock:jar:2.0.8:compile
[INFO] | +- commons-logging:commons-logging:jar:1.1:compile
[INFO] | | +- log4j:log4j:jar:1.2.12:compile
[INFO] | | +- logkit:logkit:jar:1.0.1:compile
[INFO] | | +- avalon-framework:avalon-framework:jar:4.1.3:compile
[INFO] | | \- javax.servlet:servlet-api:jar:2.3:compile
It's showing that org.springframework:spring-mock:jar:2.0.8 depends on commons-logging:commons-logging:jar:1.1 which depends on javax.servlet:servlet-api:jar:2.3. You can avoid the problem by excluding the Servlet API:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-mock</artifactId>
<version>2.0.8</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
However, rather than doing this, I'd recommend taking a step back and questioning why you're adding spring-mock to your project. It was released in 2008 and has been out of support for many years. It was part of Spring Framework 2.0.8 and the version of Spring Boot that you're using, 2.3.0.RELEASE, requires Spring Framework 5.2.x.

'[TestNG] Couldn't find the testng.xml in the jar file, running all the classes' error while running test on AWS Device Farm

I am trying to run a test suite on AWS device farm, It is a Maven project, I get the following error on the device farm Parsing result document: [TestNG] Couldn't find the testng.xml in the jar file, running all the classes.
While creating the zip for AWS device farm from Maven I get the following warning:
[WARNING] The POM for org.testng:testng:jar:5.14.3 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details.
I have the latest version of testng and surefire plugin nothing seems to help. any help on this one will be much appreciated.
My pom.xml is as follows:
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>com.pankanis.cameraplus </groupId>
<artifactId>CameraPlusApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>CameraPlusApp</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<suiteXmlFile>./testng.xml</suiteXmlFile>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/io.appium/java-client -->
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.1</version>
</dependency>
<dependency>
<groupId>com.github.genium-framework</groupId>
<artifactId>Appium-Support</artifactId>
<version>1.0.5</version>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>1.4.9</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
</dependency>
<dependency>
<groupId>com.sikulix</groupId>
<artifactId>sikulixapi</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.4.01</version>
</dependency>
<dependency>
<groupId>com.relevantcodes</groupId>
<artifactId>extentreports</artifactId>
<version>2.41.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.uncommons</groupId>
<artifactId>reportng</artifactId>
<version>1.1.4</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/dependency-jars/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>zip-with-dependencies</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/zip.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
You need to add the testng.xml to the root of the -tests.jar file created. To do this put it in the src/test/resources directory to take advantage of the super pom configuration. Alternatively, you can create some testResources tags to reference where the testng.xml is at currently.
Hope that helps
Just added a pull request here
https://github.com/awslabs/aws-device-farm-appium-tests-for-sample-app/pull/14
[update]
There is now a premium support article about this
https://aws.amazon.com/premiumsupport/knowledge-center/xml-file-tests-jar-file-device-farm/

Maven Plugin Development - Include Current Project's Resources to Plugin - "include-project-dependencies" - "NoSuchElementException"

I am trying to develop a maven plugin that uses resource files of the project that uses it as a plugin. I implemented that suggestion into my maven-plugin project and it was builded well. But when i clean & build my project that uses the plugin, i get this exception:
"Failed to execute goal
sample.plugin:maven-plugin:1.0-SNAPSHOT:convertproperties (default) on
project temp: Unable to retrieve component configurator
include-project-dependencies for configuration of mojo
sample.plugin:maven-plugin:1.0-SNAPSHOT:convertproperties:
java.util.NoSuchElementException
role: org.codehaus.plexus.component.configurator.ComponentConfigurator
roleHint: include-project-dependencies"
POM file of the maven-plugin:
<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>sample.plugin</groupId>
<artifactId>maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
<name>maven-plugin</name>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>[1.5.0, 1.5.1 ]</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0.9</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.3</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.3</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.4</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.0.9</version>
<exclusions>
<exclusion>
<artifactId>maven-artifact</artifactId>
<groupId>org.apache.maven</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>2.0.9</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>2.0.9</version>
<exclusions>
<exclusion>
<artifactId>maven-artifact</artifactId>
<groupId>org.apache.maven</groupId>
</exclusion>
<exclusion>
<artifactId>maven-repository-metadata</artifactId>
<groupId>org.apache.maven</groupId>
</exclusion>
<exclusion>
<artifactId>wagon-provider-api</artifactId>
<groupId>org.apache.maven.wagon</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-repository-metadata</artifactId>
<version>2.0.9</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-provider-api</artifactId>
<version>1.0-beta-2</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>descriptor</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>2.3</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.4</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
POM file of my project that uses the maven-plugin:
<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>temp</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>temp</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.3</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.3</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>sample.plugin</groupId>
<artifactId>maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>convertproperties</goal>
</goals>
</execution>
</executions>
<configuration>
<sourcePath>/lang</sourcePath>
<destinationPath>lang_json</destinationPath>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>src\main\webapp\lang</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>6.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
</project>
Any help would be very useful, thanks.
I have found a very good solvation to use the resources of the project inside maven-plugin.
Firstly i gave up using that suggestion.
My plugin's aim was to convert some resource (.properties) files and save them into the location where jsp pages are stored inside the project. So, first step is to copy the needed resource files and rename them as needed by using another maven-plugin called "maven-antrun-plugin" by setting it like that:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>CopyLanguagePropertiesAsJson</id>
<phase>compile</phase>
<configuration>
<tasks>
<copy file="${basedir}\src\main\resources\x.properties"
tofile="${basedir}\src\main\webapp\x\y.z" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
After that movement, I send the opened properties file and destination file into my plugin as variables typed "file" and converted the properties file and stored into the converted file ==> x.properties --> y.z
I said opened because maven does the job exactly like tihs; at build time opens the files that are set as variables for some maven-plugins and sends those objects that are references of those files. The maven-plugin gains the ability to change those files by this way.
Like this:
<plugin>
<groupId>group.id</groupId>
<artifactId>artifact-id</artifactId>
<version>x.x.x</version>
<configuration>
<properties>
<file>${basedir}\src\main\resources\x.properties</file>
</properties>
<convertedFiles>
<file>${basedir}\src\main\webapp\x\y.z</file>
</jsons>
</convertedFiles>
</plugin>
And those files are taken inside the code (class extends AbstractMojo) of my plugin like this:
/**
* #parameter
*/
private File[] properties;
/**
* #parameter
*/
private File[] convertedFiles;
Those are the steps that fully achieves the aim on converting .properties files into another files and storing inside somewhere of a project.
In addition, i have faced with an exception that tells some classes are not found while executing the maven-plugin on the build time of the project which uses it. This is caused by not being able to find needed jar files of the maven-plugin at the build time of the current project. The solvation of that is to use plugin called "maven-assembly-plugin" that builds the jar of your maven-plugin including the dependency jar libraries that your maven-plugin uses. The configuration of the plugin inside the pom file of your maven-plugin :
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
If in some cases, the plugin fails to compile your jar as described, it may be caused by not containing a main class inside your maven-plugin. Because the resason to use such plugins that compile all jar files into one is to be bale to execute the jar of the current project alone itself, not needing any other classes on runtime (building standalone jar files). So, simply create a main class that uses the class of your maven-plugin (class extends AbstractMojo) and try to compile again. After a successfull compilation you can delete your main class, it would build your maven-plugin successfully again without a main class.
I vould be very happy if this post is helpful for somebody.

Grails and Maven Integration: building war file by using maven

I can build a war file by running Grails command 'war', and the war file runs perfectly.
when it comes to maven, it doesn't work at all!
I build the project by run 'clean package', and skipped all the tests(don't know if this will affect the war)
The war file is generated in target directory, but I noticed the war file size is different from the one generated by grails command. Also when I deployed the maven generated war file onto out tomcat server, it cannot run.
Another question is do I need to add maven-war in the pom.xml? Because if I don't add the goal, it will still build a war file, what's the difference with setting up goal?
my pom file:
<properties>
<grails.version>2.1.1</grails.version>
</properties>
<dependencies>
<dependency>
<groupId>org.grails</groupId>
<artifactId>grails-dependencies</artifactId>
<version>${grails.version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.grails</groupId>
<artifactId>grails-test</artifactId>
<version>${grails.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.grails</groupId>
<artifactId>grails-plugin-testing</artifactId>
<version>${grails.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>tomcat</artifactId>
<version>${grails.version}</version>
<scope>provided</scope>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>cache</artifactId>
<version>1.0.1</version>
<scope>compile</scope>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>database-migration</artifactId>
<version>1.3.2</version>
<scope>runtime</scope>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>joda-time</artifactId>
<version>1.4</version>
<scope>runtime</scope>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>hibernate</artifactId>
<version>${grails.version}</version>
<scope>runtime</scope>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>jquery-ui</artifactId>
<version>1.8.24</version>
<scope>runtime</scope>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>jquery</artifactId>
<version>1.8.0</version>
<scope>runtime</scope>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>resources</artifactId>
<version>1.1.6</version>
<scope>runtime</scope>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>webxml</artifactId>
<version>1.4.1</version>
<scope>provided</scope>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>spring-security-core</artifactId>
<version>1.2.7.3</version>
<scope>provided</scope>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>spring-security-ldap</artifactId>
<version>1.0.6</version>
<scope>provided</scope>
<type>zip</type>
</dependency>
<!--<dependency>-->
<!--<groupId>com.rbccm.erebus</groupId>-->
<!--<artifactId>erebus</artifactId>-->
<!--<version>4.1.1-SNAPSHOT</version>-->
<!--</dependency>-->
</dependencies>
<build>
<pluginManagement/>
<plugins>
<!-- Disables the Maven surefire plugin for Grails applications, as we have our own test runner -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>surefire-it</id>
<configuration>
<skip>false</skip>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<filesets>
<fileset>
<directory>plugins</directory>
<includes>
<include>**/*</include>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.grails</groupId>
<artifactId>grails-maven-plugin</artifactId>
<version>${grails.version}</version>
<configuration>
<!-- Whether for Fork a JVM to run Grails commands -->
<skipTests>true</skipTests>
<fork>true</fork>
</configuration>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>clean</goal>
<goal>maven-war</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<!-- fix for grails bug http://jira.grails.org/browse/MAVEN-1 -->
<id>recopy-resources-after-grails</id>
<phase>package</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>grails</id>
<name>grails</name>
<url>http://repo.grails.org/grails/core</url>
</repository>
<repository>
<id>grails-plugins</id>
<name>grails-plugins</name>
<url>http://repo.grails.org/grails/plugins</url>
</repository>
</repositories>
<profiles>
<profile>
<id>tools</id>
<activation>
<property>
<name>java.vendor</name>
<value>Sun Microsystems Inc.</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>${java.version}</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
</profile>
</profiles>
I figure out that I missed a jar dependency, so the war file cannot run

Resources