Maven sonar misconfiguration, maybe missing source directory? - java

When I do a mvn clean package locally everything works fine. When I do a mvn clean package on the jenkins server I get errors. I am running Jenkins 1.596, Maven 3.2.5, SonarQube 4.5.1, Maven plug-in 2.4 is defined in the Jenkins sonar settings.
This is the output from the Jenkins job.
[INFO] --- sonar-maven-plugin:2.4:sonar (default-cli) # myproject ---
[INFO] SonarQube version: 4.5.1
INFO: Work directory: /var/lib/jenkins/workspace/myporject/target/sonar
[INFO] [22:48:12.147] Base dir: /var/lib/jenkins/workspace/myproject
[INFO] [22:48:12.148] Working dir: /var/lib/jenkins/workspace/myproject/target/sonar
[INFO] [22:48:12.148] Source paths: src
[INFO] [22:48:12.148] Test paths: src/test/java
[INFO] [22:48:12.148] Binary dirs: target/classes
[INFO] [22:48:12.148] Source encoding: UTF-8, default locale: en_US
[INFO] [22:48:12.148] Index files
[ERROR] File [relative=src/test/java/com/blah/web/service.java, abs=/var/lib/jenkins/workspace/myproject/src/test/java/com/blah/web/service.java] can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files
[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.4:sonar (default-cli) on project myproject: File [relative=src/test/java/com/blah/web/service.java, abs=/var/lib/jenkins/workspace/myproject/src/test/java/com/blah/web/service.java] can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.4:sonar (default-cli) on project myproject: File [relative=src/test/java/com/blah/web/service.java, abs=/var/lib/jenkins/workspace/myproject/src/test/java/com/blah/web/service.java] can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files
It appears that something is missing from my Sonar plug-in settings but I'm not sure what or where to define it.
Here are some snippets from 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>com.blah</groupId>
<artifactId>myproject</artifactId>
<version>99</version>
<packaging>war</packaging>
<name>myproject</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<routePath>${pom.project.build.directory}/routes</routePath>
<spring.release.version>3.2.4.RELEASE</spring.release.version>
<rabbitmq.version>3.1.4</rabbitmq.version>
<spring.amqp.version>1.2.0.RELEASE</spring.amqp.version>
</properties>
<build>
<finalName>myproject</finalName>
<sourceDirectory>src</sourceDirectory>
<scriptSourceDirectory>src/main/java</scriptSourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerId>groovy-eclipse-compiler</compilerId>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.8.0-01</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>2.1.8-01</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<additionalProjectnatures>
<projectnature>org.eclipse.jdt.groovy.core.groovyNature</projectnature>
</additionalProjectnatures>
<classpathContainers>
<classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
<classpathContainer>GROOVY_DSL_SUPPORT</classpathContainer>
</classpathContainers>
<sourceIncludes>
<sourceInclude>**/*.groovy</sourceInclude>
</sourceIncludes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18.1</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.18.1</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<includes>
<include>**/integration/**/*.class</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

The problem seems to be that your source folder is a prefix of your test folder. In other words, if you say that your test folder is src/test/java/, your source folder should be src/main/java, not src since this causes the plugin to find the same class twice, which is what causes the error
Removing <sourceDirectory>src</sourceDirectory> should do the trick since it will use maven's default (src/main/java). While you're at it, remove also testSourceDirectory since you are setting it to the default value, so you don't need it. In general the pom should be as simple as possible since maven is all about convention over configuration

Related

How to find package name once Maven dependency is added

I'm attempting to use the socket.io implementation for Java. I need 2 dependencies: 1) Engine.IO Java Server and 2) Socket.IO Server Java. I'm struggling to import the actual Java packages once the dependencies have been added to my pom.xml. Looking at the javadocs for Engine.IO Java Server, it looks like the package name to import should be io.socket.engineio.server. However, this results in an error (details below). For other dependencies that I add, what's the best way to find the package name to actually import the dependency in my Java source code?
I'm not using an IDE like IntelliJ/Eclipse. I'm just using a more simple text editor (VSCode) and a terminal. Also, I've ensured the dependencies are actually downloaded and installed in my ~/.m2/repository directory. Here are my files/terminal output.
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.mycompany.app</groupId>
<artifactId>game-server</artifactId>
<version>1.0-SNAPSHOT</version>
<name>game-server</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.socket</groupId>
<artifactId>engine.io-server</artifactId>
<version>6.1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.socket</groupId>
<artifactId>socket.io-server</artifactId>
<version>4.0.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.mycompany.app.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
App.java
package com.mycompany.app;
import io.socket.engineio.server;
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}
Terminal Output
$ mvn compile
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------< com.mycompany.app:game-server >--------------------
[INFO] Building game-server 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) # game-server ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/josh/Repos/game/game-server/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) # game-server ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /home/josh/Repos/game/game-server/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/josh/Repos/game/game-server/src/main/java/com/mycompany/app/App.java:[3,26] package io.socket.engineio does not exis

How do I externally set a version for my jar without a parent pom that produces a usable pom.xml for dependencies

How do I externally define the version tag in pom.xml for a jar project, with no parent pom?
I've used properties-maven-plugin and flatten-maven-plugin to get real close. The resulting pom.xml that gets deployed has an unusable version because of the value substitutions being used by properties-maven-plugin to set version. flatten-maven-plugin resolves issues with dependency versions, but does not seem to resolve the version of the primary artifact. The code does appear to build and name the jar correctly.
I looked into https://maven.apache.org/maven-ci-friendly.html and learned about ${revision}, but the examples there seem to include parent poms.
I'm hoping someone has come across a solution without use of a parent pom. If there's no solution, I'd like to consider this a feature request for one of the plugins, but I'd like to try here first before I submit such a request.
This is the simplest configuration I can provide to demonstrate my issue.
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>testgroup</groupId>
<artifactId>test</artifactId>
<version>${revision}</version>
<packaging>jar</packaging>
<name>test</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<lang>3.9</lang>
<revision>${major}.${minor}</revision>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${lang}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<id>pre</id>
<phase>pre-clean</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>test.properties</file>
</files>
</configuration>
</execution>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>test.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.1.0</version>
<configuration>
<flattenMode>defaults</flattenMode>
</configuration>
<executions>
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
test.properties
major=1
minor=2
src/main/java/testgroup/test/App.java
package testgroup.test;
import org.apache.commons.lang3.StringUtils;
public class App
{
public static void main( String[] args )
{
System.out.println(StringUtils.chop("boo"));
}
}
Resulting .flattened-pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>testgroup</groupId>
<artifactId>test</artifactId>
<version>${major}.${minor}</version>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
I expect the version in .flattened-pom.xml to be 1.2, not ${major}.${minor}
So, I'm not sure if this is something I'm doing wrong, or some kind of bug in one of the plugins. For example, even Maven displays this weirdly:
C:\Users\Robert\eclipse-workspace\test>mvn clean package
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------------< testgroup:test >---------------------------
[INFO] Building test ${major}.${minor}
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- properties-maven-plugin:1.0.0:read-project-properties (pre) # test ---
< snip >
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # test ---
[INFO] Building jar: C:\Users\Robert\eclipse-workspace\test\target\test-1.2.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
I don't know if you managed to find a way to resolve this, but from what I see, you are correctly setting the $revision property to the version element.
But do you run the tests? In order to build/test the application you need to run it like this:
mvn clean flatten:flatten test
or
mvn clean flatten:flatten package
What I find a bit off is that you are using $major and $minor without having them initialized in your pom.xml as properties and not using properties instead.
I understand that you would like to use the properties file which I assume you inject it somehow in your test environment. Instead you could use properties <major> and <minor> to initialize them and when you want to change them you can use
mvn clean -Dmajor=1 -Dminor=3 flatten:flatten test
If you have found some other way to resolve this, please share it with the rest of us :)
upgrade maven >= 3.5.0
change goal <phase>process-resources</phase> to <phase>package</phase>
it will solve the issue.
see also:
Maven CI Friendly Versions

Impossible to compile using maven-compiler-plugin with Java higher than 1.8

I have a NetBeans maven-based project that I want to switch from Java 1.8 to 12 but I can't compile it.
After many attempts, I have decided to start from the beginning, and create a very simple project to understand how to do this change.
Well, I have tried and I can't compile the simple project either.
Could someone explain what I am doing wrong?
Preamble
NetBeans: 10.0
JAVA_HOME: C:\Program Files\Java\jdk-12 (I have tried also 9, 10, 11)
Maven:
Project creation
Create Project with a Window (first TopComponent)
I changed the JDK version from 11 (default in NetBeans 10.0) to 12
This is the autogenerated POM with and the javax.annotation-api Dependency
<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>
<groupId>it.prj</groupId>
<artifactId>Project-parent</artifactId>
<version>2.9</version>
</parent>
<artifactId>Project-source</artifactId>
<packaging>nbm</packaging>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>nbm-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<useOSGiDependencies>true</useOSGiDependencies>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<useDefaultManifestFile>true</useDefaultManifestFile>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-netbeans-api-annotations-common</artifactId>
<version>${netbeans.version}</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-windows</artifactId>
<version>${netbeans.version}</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-util</artifactId>
<version>${netbeans.version}</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-util-ui</artifactId>
<version>${netbeans.version}</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-util-lookup</artifactId>
<version>${netbeans.version}</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-awt</artifactId>
<version>${netbeans.version}</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-netbeans-modules-settings</artifactId>
<version>${netbeans.version}</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
<type>jar</type>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Then I start the Clean & Build > SUCCESS
I changed the Java version from 1.7 to 12
This add the related Plugin to the POM
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>12</source>
<target>12</target>
</configuration>
</plugin>
Update the version field, so it becomes:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>12</source>
<target>12</target>
</configuration>
</plugin>
Then I restart the Clean & Build > FAILED
cd D:\Project\Project-source; "JAVA_HOME=C:\\Program Files\\Java\\jdk-12" "M2_HOME=C:\\Program Files\\apache-maven-3.6.0" cmd /c "\"\"C:\\Program Files\\apache-maven-3.6.0\\bin\\mvn.cmd\" -Dmaven.ext.class.path=\"C:\\Program Files\\Netbeans 10.0\\java\\maven-nblib\\netbeans-eventspy.jar\" -Dfile.encoding=UTF-8 clean install\""
Building Project-source 2.9
--- maven-clean-plugin:2.5:clean (default-clean) # Project-source ---
Deleting D:\Project\Project-source\target
--- maven-resources-plugin:3.1.0:resources (default-resources) # Project-source ---
Using 'UTF-8' encoding to copy filtered resources.
Copying 1 resource
--- maven-compiler-plugin:3.8.0:compile (default-compile) # Project-source ---
Changes detected - recompiling the module!
Compiling 1 source file to D:\Project\Project-source\target\classes
--- nbm-maven-plugin:4.1:manifest (default-manifest) # Project-source ---
NBM Plugin generates manifest
Adding OSGi bundle dependency - javax.annotation:javax.annotation-api
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Failed to execute goal org.codehaus.mojo:nbm-maven-plugin:4.1:manifest (default-manifest) on project Project-source:
Execution default-manifest of goal org.codehaus.mojo:nbm-maven-plugin:4.1:manifest failed.: IllegalArgumentException
EDIT
i have tried to remove nbm-maven-plugin as suggested but this change the structure of Project and i don't know how to reinclude this module
Please use the 4.2 version like this:
<groupId>org.apache.netbeans.utilities</groupId>
<artifactId>nbm-maven-plugin</artifactId>
<version>4.2</version>
replacing any references to:
<groupId>org.codehaus.mojo</groupId>
<artifactId>nbm-maven-plugin</artifactId>
jar file generated by jdk>8 cannot be parsed by older version of the plugin.
In your example nbm-maven-plugin fails but the compilation process is fine.
Temporarily remove nbm-maven-plugin from your build and see if Maven can build without it. Perhaps you can skip this plugin altogether as it seems specific only to NetBeans IDE.

Could not find goal 'devmode' in plugin org.codehaus.mojo

I am a beginner in GWT and Maven. I created a new GWT Application project in Eclipse. Then, I converted that project into Maven Project by right-click on Project name => Configure => Convert to Maven Project and I saw that a pom file was generated for that project. Next, I run as project as Maven build but it was not compiled since a goal was not specified there. Actually, I don't understand what exactly have I to write under that goal section, therefore, I wrote package under that and then again I built maven and it compiled successfully.
After that, I tried to run this maven project in Command Prompt on the SuperDevMode using the 2nd step mentioned on Run the GWT Project under the Setting up a new project section. But while following these steps on Command Prompt, I got an error that devmode could not be found. Here is my Command prompt log:
C:\Users\TEST>cd eclipse-workspace/MyWebApp
C:\Users\TEST\eclipse-workspace\MyWebApp>mvn war:exploded
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building MavenApp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-war-plugin:3.1.0:exploded (default-cli) # abcdef ---
[INFO] Exploding webapp
[INFO] Assembling webapp [abcdef] in [C:\Users\TEST\eclipse-workspace\MyWebApp\target\abcdef-0.0.1-SNAPSHOT]
[INFO] Processing war project
[INFO] Webapp assembled in [63 msecs]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.920 s
[INFO] Finished at: 2017-08-30T11:24:53+05:30
[INFO] Final Memory: 12M/107M
[INFO] ------------------------------------------------------------------------
C:\Users\TEST\eclipse-workspace\MyWebApp>mvn gwt:devmode
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.301 s
[INFO] Finished at: 2017-08-30T11:25:02+05:30
[INFO] Final Memory: 8M/107M
[INFO] ------------------------------------------------------------------------
[ERROR] Could not find goal 'devmode' in plugin org.codehaus.mojo:gwt-maven-plugin:2.8.1 among available goals clean, compile, compile-report, css, debug, eclipse, eclipseTest, generateAsync, help, i18n, mergewebxml, resources, run, run-codeserver, source-jar, test -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoNotFoundException
Here is my pom.xml file:
<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>MyWebApp</groupId>
<artifactId>abcdef</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<name>MavenApp</name>
<description>It is a maven app</description>
</project>
I searched a lot to resolve this error but found no solution for that issue. Please help me to fix this issue as I am very confused on how to fix it.
Edit: After further study, I used mvn gwt:run as an alternative to the command mvn gwt:devmode, but still I got another error on command prompt as given below:
[ERROR] Failed to execute goal org.codehaus.mojo:gwt-maven-plugin:2.8.1:run (default-cli) on project MyWebApp: The parameters 'runTarget' for goal org.codehaus.mojo:gwt-maven-plugin:2.8.1:run are missing or invalid
Without any more information than gwt:devmode, Maven will try to find an appropriate plugin, based on its default settings. It happens that a gwt-maven-plugin exists with org.codehaus.mojo as groupId, fitting in Maven built-in plugin resolution.
But this is not the plugin you're looking for.
You are probably trying to use this one, so just add this to your pom.xml, in the <plugins> section:
<plugin>
<groupId>net.ltgt.gwt.maven</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>1.0-rc-8</version>
<extensions>true</extensions>
<configuration>
<moduleName>com.example.app.App</moduleName>
</configuration>
</plugin>
Adapting the moduleName if needed.
Well, I was able to solve this issue by copying some dependencies, plugin, and configuration from the pom.xml file (which is generated in the project created by the webAppCreator using maven) to the pom.xml file of my project created in the Eclipse. So, this is my pom.xml file created finally:
<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>MyPersonalProject</groupId>
<artifactId>MyPersonalProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<!-- Setting maven.compiler.source to something different to 1.8
needs that you configure the sourceLevel in gwt-maven-plugin since
GWT compiler 2.8 requires 1.8 (see gwt-maven-plugin block below) -->
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<!-- Don't let your Mac use a crazy non-standard encoding -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencyManagement>
<dependencies>
<!-- ensure all GWT deps use the same version (unless overridden) -->
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt</artifactId>
<version>2.8.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-dev</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>net.ltgt.gwt.maven</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>1.0-rc-6</version>
<executions>
<execution>
<goals>
<goal>import-sources</goal>
<goal>compile</goal>
<goal>import-test-sources</goal>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<moduleName>mypackage.MyPersonalproject</moduleName>
<failOnError>true</failOnError>
<!-- GWT compiler 2.8 requires 1.8, hence define sourceLevel here if you use
a different source language for java compilation -->
<sourceLevel>1.8</sourceLevel>
<!-- Compiler configuration -->
<compilerArgs>
<!-- Ask GWT to create the Story of Your Compile (SOYC) (gwt:compile) -->
<arg>-compileReport</arg>
<arg>-XcompilerMetrics</arg>
</compilerArgs>
<!-- DevMode configuration -->
<warDir>${project.build.directory}/${project.build.finalName}</warDir>
<classpathScope>compile+runtime</classpathScope>
<!-- URL(s) that should be opened by DevMode (gwt:devmode). -->
<startupUrls>
<startupUrl>MyPersonalProject.html</startupUrl>
</startupUrls>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
When I run this application using maven in the Command Prompt, it ran successfully except showing 2 or 3 warnings in the Command Prompt log. Also, I noticed that the SNAPSHOT generated in the version is different for the pom.xml created by Eclipse as compared to the one created by the maven project on command prompt.

Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.3.2:exec (default) on project mavenproject2:

I am beginning the initial attempt to use Vert.x in Java. IDE is Netbeans version 8.1. Vert.x is version 3.0.0. The code for this project is shown below. The pom.xml file is also listed below. This code will run in Netbeans IDE but the Build (for jar file) will not complete without the error shown in the BUILD REPORT below. Thus, the generated jar file will not execute. I have researched every resource I could locate on the internet and cannot find an adequate solution/answer. I would appreciate any help anybody can offer to resolve this problem.
The POM file is generated by Netbeans IDE when creating a new project:
File - New Project - Maven - Project from Archetype - vertx-java-archetype
I then added the main() method.
DETAILED BUILD ERROR REPORT:
--- maven-jar-plugin:2.3.2:jar (default-jar) # mavenproject2 ---
Building jar: C:\Projects\GenMatchJ\mavenproject2\target\mavenproject2-1.0-SNAPSHOT.jar
--- maven-shade-plugin:2.3:shade (default) # mavenproject2 ---
Including io.vertx:vertx-core:jar:3.0.0 in the shaded jar.
Including io.netty:netty-common:jar:4.0.28.Final in the shaded jar.
Including io.netty:netty-buffer:jar:4.0.28.Final in the shaded jar.
Including io.netty:netty-transport:jar:4.0.28.Final in the shaded jar.
Including io.netty:netty-handler:jar:4.0.28.Final in the shaded jar.
Including io.netty:netty-codec:jar:4.0.28.Final in the shaded jar.
Including io.netty:netty-codec-http:jar:4.0.28.Final in the shaded jar.
Including com.fasterxml.jackson.core:jackson-core:jar:2.5.3 in the shaded jar.
Including com.fasterxml.jackson.core:jackson-databind:jar:2.5.3 in the shaded jar.
Including com.fasterxml.jackson.core:jackson-annotations:jar:2.5.0 in the shaded jar.
Including io.vertx:vertx-web:jar:3.0.0 in the shaded jar.
Including io.vertx:vertx-auth-common:jar:3.0.0 in the shaded jar.
--- exec-maven-plugin:1.3.2:exec (default) # mavenproject2 ---
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 3.290s
Finished at: Sun Jun 05 13:01:40 EDT 2016
Final Memory: 30M/313M
------------------------------------------------------------------------
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.3.2:exec (default) on project mavenproject2: The parameters 'executable' for goal org.codehaus.mojo:exec-maven-plugin:1.3.2:exec are missing or invalid -> [Help 1]
To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.
For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginParameterException
POM.XML FILE:
<?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.ssp</groupId>
<artifactId>mavenproject2</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-dependencies</artifactId>
<version>3.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>io.vertx.core.Starter</Main-Class>
<Main-Verticle>com.ssp.mavenproject2.Main</Main-Verticle>
</manifestEntries>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/services/io.vertx.core.spi.VerticleFactory</resource>
</transformer>
</transformers>
<artifactSet></artifactSet>
<outputFile>${project.build.directory}/mavenproject2-${project.version}-fat.jar</outputFile>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.2</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>io.vertx.core.Starter</mainClass>
<additionalClasspathElements>
<additionalClasspathElement>${basedir}/src/main/java/</additionalClasspathElement>
</additionalClasspathElements>
<systemProperties>
<systemProperty>
<key>vertx.deployment.options.redeploy</key>
<value>true</value>
</systemProperty>
<systemProperty>
<key>vertx.deployment.options.redeployScanPeriod</key>
<value>100</value>
</systemProperty>
</systemProperties>
<arguments>
<argument>run</argument>
<argument>com/ssp/mavenproject2/Main.java</argument>
<!-- <argument>-cluster</argument>
<argument>-cluster-host</argument>
<argument>127.0.0.1</argument>-->
</arguments>
</configuration>
</plugin>
</plugins>
</build>
<name>MainSsp</name>
<description>Main entry point for SSP Example with embedded Vert.x</description>
</project>
SOURCE CODE:
package com.ssp.mavenproject2;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Vertx;
import javax.swing.JOptionPane;
/**
*
*/
public class Main extends AbstractVerticle {
public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "This Vert.x/Java integration is UUUGGGGHH tough without documentation...");
// Create an HTTP server which simply returns "Hello World!" to each request.
Vertx.vertx().createHttpServer().requestHandler(req -> req.response().end("Hello World!")).listen(8080);
Vertx.vertx().setPeriodic(3000, res -> {
System.out.println("Periodic event triggered.");
});
try{
Thread.sleep(30000);
}catch(Exception e)
{
System.out.println("Exception caught");
}
}
#Override
public void start() throws Exception {
vertx.setPeriodic(3000, res -> {
System.out.println("Periodic event triggered.");
});
}
}
It looks you're trying to run mvn exec:exec but for that you need to specify the executable (the error you're getting). In that case the executable should be your java binary, e.g.: /usr/java/latest/bin/java if you're using linux and the Oracle RPM.
Alternatively you should do: mvn exec:java which knows that the executable is java and knows how to pick the classpath dependencies from the pom file.
Now if you pay attention to your code you'll see that the public static void main method is never called, your exec plugin use the vert.x starter not your class, so when your app starts there won't be any server, just the periodic code executed inside the start method.
If you execute your main, then you're still missing to deploy your verticle so you have the server but no periodic task, in order to achieve that you need to add:
vertx.deployVerticle(Main.class.getName());
Allow Netbeans to index the maven repository at
~\.m2\repository\org\codehaus\mojo
after the repository gets indexed everything should work fine.

Categories

Resources