I am building an android app and I am trying to use external libraries (jar).
When I build project it throws
bad class file magic or version
I checked pom.xml files and I noticed that in the one jar it has the following
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
while in the other
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
Could this justify the error?
I think that's because You can't use Java8 code in java7 project.
Related
Working on multi-module maven project. Have maven-compiler-plugin used in parent pom as follows:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
Want to use <version>3.1</version> in the main project pom due to its incremental compile support. Do not have write access in parent pom. How can i just configure plugin in main project pom to use new version?
You can override the plugin in submodule
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
I have a custom Maven plugin which makes use of JDK 12 preview features. I compile the plugin setting --enable-preview as compiler arg, i.e.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>
<compilerArg>--enable-preview</compilerArg>
</compilerArgs>
</configuration>
</plugin>
When I want to execute the plugin, I add the plugin like this in the POM:
<plugin>
<groupId>my.group</groupId>
<artifactId>my-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>my-goal</goal>
</goals>
</execution>
</executions>
</plugin>
But this fails with:
Preview features are not enabled for MyPluginMojo. Try running with '--enable-preview'
How can I enable preview features in a plugin execution?
For me, I had to add a config file to my build directory at:
.mvn/jvm.config
containing:
--enable-preview
This will make sure that Maven passes the correct parameters to JVM
You made a mistake in your pom. <compilerArgs> takes nested <arg>, like so:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>17</source>
<target>17</target>
<compilerArgs>
<arg>--enable-preview</arg>
</compilerArgs>
</configuration>
</plugin>
For JDK 17, this works for me:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>17</source>
<target>17</target>
<compilerArgs>--enable-preview</compilerArgs>
</configuration>
</plugin>
Possible to target only one of the two TestNG xml files listed within my Maven POM File?
My Maven POM file points to two xml files: uat.xml and preprod.xml, how do i target only one of the xml files using maven commands such as mvn clean compile test?
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<fork>true</fork>
<!--<executable>C:\Program Files\Java\jdk1.8.0_121\bin\javac.exe</executable> -->
<executable>${env.JAVA_HOME}\bin\javac.exe</executable>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>uat.xml</suiteXmlFile>
<suiteXmlFile>preprod.xml</suiteXmlFile>
</suiteXmlFiles>
<testErrorIgnore>false</testErrorIgnore>
<testFailureIgnore>false</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
See below. You will reference the file by name. So,
mvn clean test -Dtestfile=uat.xml
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${testfile}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
In the program like
entities.stream().filter(m->m.getId()==id).findAny().get();
where entities is a List. After setting all the libraries and other SDKs to Java 8. we are getting the error as:
use -source 8 or higher to enable lambda expressions
This is how solved my problem by adding the below plugin settings in my parent POM file.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
In case of my project I need to create new classes after each compilation. For compilation I'm using maven compiler plugin 3.1. I tried to use compilerReuseStrategy = alwaysNew option but it didn't make any affect, it always compile only changed classes. Here is plugin declaration in pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerReuseStrategy>alwaysNew</compilerReuseStrategy>
</configuration>
</plugin>
An I doing something wrong or that's a bug and this option really doesn't work?
If you are talking about the incremental feature fo the maven-compiler-plugin you can change this behaviour by the following configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<useIncrementalCompilation>false</useIncrementalCompilation>
</configuration>
</plugin>
The compileReuseStrategy in contradiction is intended to define the behaviour in relationship with multi-threaded running of the compiler.
What about using mvn clean install?