I'm fairly new to maven, so bear with me.
I have this dependency in pom.xml
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_core</artifactId>
<version>5.4.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.jmeter/ApacheJMeter_java -->
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_java</artifactId>
<version>5.4.3</version>
</dependency>
These dependencies contain log4j version 2.11.2 and i want to update them to atleast 2.17.1 (i think thats the latest version, not sure).
Is there a way to explicitly update these version numbers, as 5.4.3 is the latest version of jmeter core and its not log4j compliant.
I use the plugin
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>3.1.0</version>
and that isnt updating to 5.4.3 either. i kinda need some help making this jmeter code log4j compliant.
Try adding dependency as dependency-management in your POM.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.log4j</groupId>
<artifactId>log4j-artifactid</artifactId>
<version>${log4j-version}</version>
</dependency>
</dependencies>
</dependencyManagement>
jmeter-maven-plugin version 3.1.0 will give you JMeter 5.3 no matter what you specify in the <dependencies> section.
The latest version is 3.5.0 which gives you JMeter 5.4.1
So you will either need to wait for the next release or to explicitly specify the desired JMeter version like:
<configuration>
<jmeterVersion>5.4.3</jmeterVersion>
</configuration>
Full pom.xml just in case
<?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>org.example</groupId>
<artifactId>jmeter-maven</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>3.5.0</version>
<executions>
<!-- Generate JMeter configuration -->
<execution>
<id>configuration</id>
<goals>
<goal>configure</goal>
</goals>
</execution>
<!-- Run JMeter tests -->
<execution>
<id>jmeter-tests</id>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
<!-- Fail build on errors in test -->
<execution>
<id>jmeter-check-results</id>
<goals>
<goal>results</goal>
</goals>
</execution>
</executions>
<configuration>
<jmeterVersion>5.4.3</jmeterVersion>
</configuration>
</plugin>
</plugins>
</build>
</project>
More information: How to Use the JMeter Maven Plugin
Related
I run a Hadoop app with the following pom.xml file. The file contains all the info for creating the JAR file and required dependencies. The file is provided below:
<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.test.hadoop.wordcount</groupId>
<artifactId>wordcount</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>wordcount</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- Hadoop -->
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.test.hadoop.wordcount.WordCount</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
</plugin>
</plugins>
</build>
</project>
When I run the app, it does create the JAR file wordcount.jar in the location,
However, I would like to attach the snapshot version with the JAR name ie. wordcount-0.0.1-SNAPSHOT.jar.
How do I achieve that? I don't have a lot of understanding of the snapshot versioning. I provided the Updated pom.xml file now.
UPDATE
I added the shade plugin but this doesn't solve the issue. Also, there is no JAR in the target directory.
Intellij w/ Maven generates the versioned JAR under target folder
Note: Since you're not using the Shade plugin, then your JAR shouldn't contain the dependencies that you may need
Attempting to get one jacoco report that will show all the results from multiple modules.
I am able to see that each of the sub-modules have a jacoco.exec after building the project but unsure of how to get it to output one report that will have all the results from every module combined.
This is what I have included in my Root pom.xml:
<plugin>
<groupId>#project.groupId#</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>#project.version#</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
I created a new module explicitly for reporting purposes. (e.g. report-aggregate-module)
Deleted the group ids and used generic artifact ids for this example:
This is what I put in the pom.xml for this report-aggregate sub-module:
<?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>
<parent>
<artifactId>report-aggregate</artifactId>
<groupId>com.name.group</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>report-aggregate</artifactId>
<name>Report Aggregate</name>
<properties>
<wildfly.version>10.0.0.Final</wildfly.version>
<wildfly.artifactId>wildfly-dist</wildfly.artifactId>
</properties>
<dependencies>
<dependency>
<groupId></groupId>
<artifactId>sub-module1</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId></groupId>
<artifactId>sub-module2</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId></groupId>
<artifactId>sub-module3</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId></groupId>
<artifactId>sub-module4</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>report-aggregate</id>
<phase>verify</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Everything seems to compile okay, the jacoco exec doesn't seem to get created for the report-aggregate-module. Anyone know a solution to this or if I'm doing this incorrectly?
Sorry if this comes a late answer.
I assume that your root pom.xml is an aggregater, with <modules> consisting of module1, module2, and report-aggregate. This is the cause of your trouble: as your root pom.xml is an aggregator, it runs JaCoCo BEFORE your submodules do, so your final report is empty. You should:
Move the configuration of goal report-aggregate of the jacoco-maven-plugin from the root POM to the report-aggregate POM. This should do the trick, because your report-aggregate POM uses <dependencies>, not <modules>.
Keep the configuration of goal prepare-agent of the jacoco-maven-plugin in the root POM.
I suggest you look at the JaCoCo forum https://groups.google.com/forum/#!topic/jacoco/FpdLbxsXSTY. It refers to a complete demo integration test https://github.com/jacoco/jacoco/tree/master/jacoco-maven-plugin.test/it/it-report-aggregate.
My application is split between users on Java 1.6u45 and Java 1.8. Our problem is that we cannot specify the project system library and have two different compiler settings for the code at the same time.
Project Structure:
Project >
> src/main/java/com/us/javafx/... (Java 8 code)
> src/main/java/com/us/... (Java 6 code)
> src/main/resources/...
Our POM.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.us</groupId>
<artifactId>PROJECT</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>PROJECT</name>
<description>DESCR</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
</dependencies>
<build>
<plugins>
<!-- Copy all dependencies to jars directory -->
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/jars</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!-- Maven Compiler -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<!-- Necessary to avoid setting JRE on Maven project update! -->
<!-- SEE PHOTO FOR WHY THIS IS HERE -->
<source>1.8</source>
<target>1.8</target>
</configuration>
<executions>
<!-- Compile Java 6 directory -->
<execution>
<id>java6</id>
<configuration>
<excludes>
<exclude>com/us/javafx/**/*</exclude>
</excludes>
<!-- Non working attempt to set compiler version -->
<source>1.6</source>
<target>1.6</target>
</configuration>
</execution>
<!-- Compile Java 8 directory -->
<execution>
<id>java8</id>
<configuration>
<includes>
<include>com/us/javafx/**/*</include>
</includes>
<!-- Non working attempt to set compiler version -->
<source>1.8</source>
<target>1.8</target>
</configuration>
</execution>
</executions>
</plugin>
<!-- Create JAR in jars folder -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<outputDirectory>${project.build.directory}/jars</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
If we tell the Maven compiler plugin to use Java 1.8, Java 1.6 users get the unsupported major minor version error. Or we tell the Maven compiler plugin to use Java 1.6 but our Java 8 code will complain about errors when performing Right Click Project > Maven > Update Project... (which causes the screen shot below):
Is there a way we can achieve both:
1) Compile Java 6 and 8 code with their respective compilers
2) Choose Java 8 as our project's JRE System Library
I recently learned about toolchains.xml. Maven has it even documented and supports it from 2.0.9! See toolchains documentation
So I added a toolchain.xml file to my ~/.m2/ folder with following content:
<toolchains xmlns="http://maven.apache.org/TOOLCHAINS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/TOOLCHAINS/1.1.0 http://maven.apache.org/xsd/toolchains-1.1.0.xsd">
<!-- JDK toolchains -->
<toolchain>
<type>jdk</type>
<provides>
<version>1.8</version>
<vendor>sun</vendor>
</provides>
<configuration>
<jdkHome>/opt/java8</jdkHome>
</configuration>
</toolchain>
<toolchain>
<type>jdk</type>
<provides>
<version>1.7</version>
<vendor>sun</vendor>
</provides>
<configuration>
<jdkHome>/opt/java7</jdkHome>
</configuration>
</toolchain>
</toolchains>
It allows you to define what different JDKs Maven can use to build the project irrespective of the JDK Maven runs with. Sort of like when you define JDK on project level in IDE. I used it when I needed to build another project with Java 7 while having Java 8 as a default.
I guess this can solve your issue.
Maven profiles is the simplest and most effective one.
You can elect and run them from your IDE too.
You design a profile for each different JDK you need. You put in each different JDK profile :
properties like source code target
dependencies that are specialised for that profile.
Project
+properties
+dependencies
+Profiles
Profile JDK8
+jdk8-properties
jdk.version
maven.compiler.source
maven.compiler.target
+jdk8-dependencies
Profile JDK11
+jdk11-properties
jdk.version
maven.compiler.source
maven.compiler.target
+jdk11-dependencies
Picture of maven profiles tree
And an example
<project>
<name>x</name>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.1.210</version>
</dependency>
</dependencies>
<profiles>
<!-- different Java versions -->
<profile>
<id>jdk8</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<jdk.version>1.8</jdk.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core-jakarta</artifactId>
<version>5.6.10.Final</version>
</dependency>
<!-- needed if jakarta is used -->
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.25</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>jdk11</id>
<properties>
<jdk.version>11</jdk.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
<version>6.1.2.Final</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.4.2</version>
</dependency>
</dependencies>
</profile>
</profiles>
<properties>
<failOnMissingWebXml>false</failOnMissingWebXml>
<junit-version>4.13.2</junit-version>
</properties>
</project>
I am trying to configure maven to build a runnable jar.
The project that this is about contains a couple of dependencies as well as embedded jetty.
I want to embed all dependencies (which works) and have one executable jar.
I can run the project fine from eclipse but once I try to run the jar I get ClassNotFoundExceptions on org.eclipse.jetty.servlet.ServletContextHandler.
However, when I use the maven-plugin and run exec:java the program starts without problems.
What am I doing wrong?
Here is a copy of my 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>comms</groupId>
<artifactId>comms-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Air</name>
<properties>
<jettyVersion>9.2.7.v20150116</jettyVersion>
<gsonVersion>2.3.1</gsonVersion>
<logjVersion>2.1</logjVersion>
<lombokVersion>1.16.2</lombokVersion>
</properties>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jettyVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gsonVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${logjVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${logjVersion}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombokVersion}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<goals><goal>java</goal></goals>
</execution>
</executions>
<configuration>
<mainClass>comms.Loader</mainClass>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<mainClass>comms.Loader</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
I noted that you declared jetty-maven-plugin as a dependency, not a plugin declaration. The jetty-maven-plugin depends on Jetty and that (i.e. the transitive dependency on Jetty) is how the Jetty classes get pulled into the Maven classpath.
However that dependency is declared as 'provided', which basically says: "my code is dependent on this, but normally it will be provided by the deployment environment". Maven will pull in the dependency because it needs it for building your source (which is probably why the exec plugin does work), but will not include it in your jar, because you specifically told it to do so.
Seems to me your pom simply does not reflect the situation:
If your code depends on Jetty classes (not the plugin), remove the
jetty-maven-plugin dependency and declare Jetty itself as an
explicit dependency.
Do not define the scope as 'provided' unless
the deployment environment really does provide the Jetty classes
(which it doesn't, given the error).
Hope this helps!
Can somebody guide me on how to integrate Maven with GWT or point to a good, workable tutorial?
I am using GWT 2.1, Eclipse 3.6 Helios
There's a Maven GWT plugin/mojo that you can use along with an archetype that will generate some sample code (which you can get rid of easily). The documentation on the site is fairly decent
http://mojo.codehaus.org/gwt-maven-plugin/
Also, I faced several problems while trying to build a WAR and get it deploy successfully on tomcat. I found this discussion on the forum to be extremely useful. The OP on this even posted a working POM
https://groups.google.com/d/topic/google-web-toolkit/j8Jgp4ZQduk/discussion
Here's a baseline POM for a GWT project in Maven:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>myCompany</groupId>
<artifactId>myModule</artifactId>
<packaging>war</packaging>
<name>My GWT App</name>
<version>1.0-SNAPSHOT</version>
<properties>
<gwtVersion>2.1.0</gwtVersion>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.1.0-1</version>
<configuration>
<module>com.myCompany.myModule</module>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwtVersion}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
The GWT Maven Plugin has a lot of additional functionality - see the project documentation for more details.