Maven error: Failed to run the ecj compiler: Unrecognized option : --patch-module - eclipse

I'm using Maven in Eclipse for a modular Java project, and have managed to make Maven use the Eclipse compiler following the answer to this question.
However, the Maven test-compile target fails with the error message
Failed to run the ecj compiler: Unrecognized option : --patch-module
which is quite surprising (actually unbelievable) because Eclipse is well up to patching modules.
Here's the pom.xml for a MVE, consisting of a modular project patchmodule:
<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>
<groupId>patchmodule</groupId>
<artifactId>patchmodule</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<compilerId>eclipse</compilerId>
<release>16</release>
<compilerArguments>
<properties>${project.basedir}/.settings/org.eclipse.jdt.core.prefs</properties>
</compilerArguments>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-eclipse</artifactId>
<version>2.12.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>ecj</artifactId>
<version>3.31.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
The error kicks in as soon as you give the project a single test, such as
package patchmodule.test;
import static org.junit.jupiter.api.Assertions.*;
class Test {
#org.junit.jupiter.api.Test
void test() {
fail("Not yet implemented");
}
}
and then do a Maven install, or any target that will invoke testCompile.
Is this a bug (and if so, whose)? More importantly, is there a way to work around it? Any help is much appreciated.

Related

Maven : Invalid element name : build

I am new to the maven tool. I am trying automation testing using maven in eclipse. As instructed by a YouTube video, I added a few dependencies in the pom.xml file. When I added the plugins under the build element, I am getting an error saying "Invalid element name : build".
The error says "*Multiple markers at this line
Invalid element name:
build
One of the following is expected:
dependency
Error indicated by:
{http://maven.apache.org/POM/4.0.0}
with code:
Malformed POM D:\Eclipse\Automation\pom.xml: Unrecognised tag: 'build' (position: START_TAG seen ...\r\n\r\n... #23: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>
<groupId>com.ll.test</groupId>
<artifactId>Automation</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Automation</name>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.6.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-chrome-driver -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>4.2.2</version>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
</plugin>
</plugins>
</build>
</dependencies>
</project>
You put the build tag into the dependencies area. Close the tag dependencies after the last dependency.
...
<dependencies>
...
</dependency>
</dependencies>
<build>
...
</build>

Maven breaks resource stream to jpg once exported to runnable jar

I've been seen searching high and low for a solution to my problem with maven (which I'm inexperienced with) including various plugins and resource declarations, all unsuccessful. I'm using JavaFX in my application and loading this image works great in eclipse but breaks once exported to a runnable jar. I'm assuming this has something to do with the way maven packages the jar.
public void initialize(){
Image image = new Image(this.getClass().getResourceAsStream("pcoordinatesImage.jpg"));
diagramImage.setImage(image);
}
I get a NullPointerException: "input must not be null" when executing the jar on command line
I've swapped out more plugins than a glade air freshener in my pom.xml file. I posted the whole pom.xml so you guys can see how little I know and maybe spot some obvious errors
<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>EllipsoidCalculation</groupId>
<artifactId>EllipsoidCalculation</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.10.19</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<filtering>false</filtering>
<directory>src/main</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>ellipsoidCalc.EllipsoidCalcMain</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
The resources are right next to the source code where I want them when I export to a jar so I have no idea why is doesn't work
Thanks for any help!
Heres the contents of my runnable jar file:
command line
I regret to admit that I found the bug. The "p" in "pcoordinatesImage.jpg" should be capitalized as shown in the screen shot of the command line. That fixed the problem. Oddly enough it didn't break the code in eclipse tho. So anyone else suffering from the same problem, check caps. The pom.xml that was posted appears to be functional, hope it helps

In IntelliJ Scala plugin, can I use scala-compiler.jar retrieved via <dependency> in `pom.xml`?

In IntelliJ, I created a blank Maven project, and added to pom.xml:
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-compiler</artifactId>
<version>2.11.0-M3</version>
<scope>compile</scope>
</dependency>
I then went to Project Settings -> Modules -> + -> Scala, and specified the compiler jar from the drop-down menu as Maven: org.scala-lang:scala-compiler:2.11.0-M3. I receive the error:
Compiler library: no scala-library*.jar found
Of course, scala-library-2.11.0-M3.jar is among the dependencies (transitively), but not stored in the same folder as scala-compiler-2.11.0-M3.jar, which is what seems to be confusing the Scala plugin.
Is there any way to use scala-compiler*.jar downloaded from a pom.xml dependency? Perhaps by manually specifying where to find each JAR?
Before this, I had been using scala-compiler*.jar downloaded via Project Settings -> Libraries -> + -> From Maven. This seems to work because IntelliJ sticks all the downloaded JARs in the same folder, which is what the Scala plugin assumes. Simply for aesthetic reasons I would like to know if it can be done with pom.xml.
You don't need the scala-compiler as a dependency to be able to build the scala project (neither using maven at command line nor by building from Build | Make Project in IntelliJ).
This is a very simple pom.xml that I use for scala projects where I don't have scala installed at all and just point IntelliJ to this pom and then I can compile and run any scala code directly from within IntelliJ.
<?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>com.stackoverflow</groupId>
<artifactId>scala-app</artifactId>
<version>1.0-SNAPSHOT</version>
<name>${project.artifactId}-${project.version}</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<scala.version>2.10.1</scala.version>
</properties>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.15.2</version>
<executions>
<execution>
<id>scala-compile</id>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
<configuration>
<args>
<arg>-make:transitive</arg>
<arg>-dependencyfile</arg>
<arg>${project.build.directory}/.scala_dependencies</arg>
</args>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

Can't compile style.scss with sass-maven-plugin

I would like to use sass-maven-plugin to compile some SASS Template style.scss into css style.css. I have added the plugin to my pom.xml build.plugins as it is descriped here. My pom.xml looks like this:
<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.company.web</groupId>
<artifactId>scss</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>scss</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.4</source>
<target>1.4</target>
</configuration>
</plugin>
<!-- To use the plugin goals in your POM or parent POM -->
<plugin>
<groupId>org.jasig.maven</groupId>
<artifactId>sass-maven-plugin</artifactId>
<version>1.1.0</version>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat6-maven-plugin</artifactId>
<version>2.1</version>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
I run the project with eclipse (right mouseclick on the project -> run as -> run Configuration -> and give as Goals : sass:update-stylesheets
eclipse prints the following error:
[ERROR] Failed to execute goal org.jasig.maven:sass-maven-plugin:1.1.0:update-stylesheets (default-cli) on project scss: The parameters 'resources' for goal org.jasig.maven:sass-maven-plugin:1.1.0:update-stylesheets are missing or invalid
What did I do wrong?
You need to add configuration to the plugin to tell it where the files to compile are and where to put the compiled files.
See resources in http://developer.jasig.org/projects/sass-maven-plugin/1.1.1/update-stylesheets-mojo.html

Why can't maven plugin work with eclipse java compiler?

I installed m2eclipse plugin in my eclipse.I have a java project in eclipse. Then I add a pom.xml into the root folder of my project. Convert my project into maven project. Now the problem comes: I can download jar contained in pom.xml, but can't import it into my java file.
Always got java compile error in my project. In package explorer view,I can see maven dependencies.
I have tried this:maven clean, restart eclipse, project clean.
Here is 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>TomLabs</groupId>
<artifactId>TomLabs</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>test</name>
<description>Tom source code</description>
<build>
<plugins>
<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>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax.media</groupId>
<artifactId>jmf</artifactId>
<version>2.1.1e</version>
</dependency>
</dependencies>
</project>
One possibility could be the package/class what you are trying to import is not available in the version of the jar file you have mentioned in the pom.xml.