Maven compiler plugin - send parameters to javac (classpath or cp) - maven

Is it possible to send arguments to javac through maven compiler plugin?
I want to set three classpaths as a argument to javac but maven returns
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project wplex-frameworks: Compilation failure
[ERROR] javac: invalid flag: classpath=*:.
[ERROR] Usage: javac <options> <source files>
Code:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler.version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<fork>true</fork>
<executable>/usr/lib/jvm/java-8-openjdk-amd64/bin/javac</executable>
<compilerArgs>
<arg>classpath=*:.</arg>
<arg>-verbose</arg>
<arg>-Xlint:all,-options,-path</arg>
</compilerArgs>
<excludes>
<exclude>x/y/z/**</exclude>
</excludes>
</configuration>
</plugin>
I have tried so far classpath=:. , -classpath=:. , -classpath *:.
The other arguments are fine.

Related

How can I override properties for test-aggregate-no-fork?

I configured different version for main and test.
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>${maven.compiler.source}</maven.compiler.target>
<maven.compiler.release>${maven.compiler.target}</maven.compiler.release>
<maven.compiler.testSource>17</maven.compiler.testSource>
<maven.compiler.testTarget>${maven.compiler.testSource}</maven.compiler.testTarget>
<maven.compiler.testRelease>${maven.compiler.testTarget}</maven.compiler.testRelease>
When I do the site, the plugin complains.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-site-plugin:4.0.0-M3:site (default-site) on project ...: Error generating maven-javadoc-plugin:3.4.1:test-aggregate-no-fork report:
[ERROR] Exit code: 1 - Loading source files for package ...
[ERROR] Loading source files for package ...
[ERROR] Loading source files for package ...
[ERROR] /.../src/test/java/.../Some.java:16: warning: as of release 10, 'var' is a restricted type name and cannot be used for type declarations or as the element type of an array
[ERROR] final var found = repositoryInstance().findAllBy...(' ', Pageable.unpaged());
[ERROR] ^
I tried with following execution and got no luck.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.4.1</version>
<configuration>
</configuration>
<executions>
<execution>
<id>default-test-aggregate-no-fork</id>
<configuration>
<source>${maven.compiler.testSource}</source>
</configuration>
</execution>
</executions>
</plugin>

How to disable a flag in maven compiler plugin?

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project AusPost: Compilation failure
[ERROR] javac: invalid flag: -s
[ERROR] Usage: javac
I am not providing any tag to the maven compiler plugin in my pom.xml. Still it is throwing error saying invalid flag -s.
How to get rid of this?
POM.XML ->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
Usually, -s comes for settings.xml of maven, but you have to provide more info in order to understand your question.

Test Case pass while running in eclipse with Junit but fails with mvn install

When i run the testcase with Junit it passes but failing with mvn install.
assertEquals(2, flight.getDelayCodes().getLocal().size());
[ERROR] Failures:
[ERROR] FlightEventHandlerTest.testDelayCodesUpdateFields:302 expected:<2> but was:<0>
I tried by adding junit dependecny, still same error
tried with surefire plugin still same error
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkMode>always</forkMode>
<forkCount>4</forkCount>
<argLine>${argLine}</argLine>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<includes>
<include>**/*Test.java</include>
</includes>
<runOrder>failedfirst</runOrder>
</configuration>
</plugin>
After few hours of debugging, building the dependency projects again made trick.Worked for me.

Maven Wrapper and generated

I want to add maven wrapper to my code
https://www.baeldung.com/maven-wrapper
mvn -N io.takari:maven:wrapper
But when executing it, it gives me an error with the classes that my plugin generates "maven-processor-plugin"
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<!-- source output directory -->
<outputDirectory>src/main/generated</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Execute
./mvnw clean install
Error
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project elser30: Compilation failure: Compilation failure:
[ERROR] Problem with Filer: Attempt to recreate a file for type com.xxx.domain.PeticionUsuario_
[ERROR] Problem with Filer: Attempt to recreate a file for type com.xxx.domain.Puesto_
[ERROR] Problem with Filer: Attempt to recreate a file for type com.xxx.domain.DatoAuxiliar_

JDK7, mvn-3.2.2 - maven-enforcer-plugin - RequireJavaVersion failed

I'm using JDK 1.7.0_60 and maven-3.2.2. When I run mvn clean install on my project new-project, I get the following error-
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # new-project ---
[INFO]
[INFO] --- maven-enforcer-plugin:1.3.1:enforce (default) # new-project ---
[WARNING] Rule 0: org.apache.maven.plugins.enforcer.RequireJavaVersion failed with message:
Detected JDK Version: 1.7.0-60 is not in the allowed range [1.5,1.6,1.7.0-60).
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.621 s
[INFO] Finished at: 2014-07-10T20:37:32+05:30
[INFO] Final Memory: 7M/18M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:1.3.1:enforce (default) on project new-project: Some Enforcer rules have failed.
Look above for specific messages explaining why the rule failed. -> [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/MojoExecutionException
Here are parts of my pom.xml as I cannot share the complete content-
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<showDeprecation>true</showDeprecation>
<source>1.7.0-60</source>
<target>1.7.0-60</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<classpathContainers>
<classpathContainer>
org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5
</classpathContainer>
</classpathContainers>
<additionalConfig>
<file>
<name>
.settings/org.eclipse.core.resources.prefs
</name>
<content>
eclipse.preferences.version=1${line.separator}encoding/<project>=UTF-8${line.separator}
</content>
</file>
</additionalConfig>
<downloadSources>true</downloadSources>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<configuration>
<rules>
<requireJavaVersion>
<version>[1.5,1.6,1.7.0-60)</version>
</requireJavaVersion>
<requireMavenVersion>
<version>[3.2.2,)</version>
</requireMavenVersion>
</rules>
</configuration>
<executions>
<execution>
<goals>
<goal>enforce</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<sourcepath>
${project.basedir}/src/main/javadoc;${project.basedir}/src/main/java
</sourcepath>
<charset>UTF-8</charset>
<docencoding>UTF-8</docencoding>
<docfilessubdirs>true</docfilessubdirs>
<links>
<link>
http://docs.oracle.com/javase/7/docs/api/
</link>
</links>
<source>1.7.0-60</source>
<show>protected</show>
</configuration>
<reportSets>
<reportSet>
<reports>
<report>javadoc</report>
</reports>
</reportSet>
</reportSets>
</plugin>
If you want to include version 1.7.0-30 in the accepted range, then you have to use square brackets when you declare the range. And you can leave out version 1.6 as it is included in the range:
<requireJavaVersion>
<version>[1.5,1.7.0-60]</version>
</requireJavaVersion>

Resources