I want to use maven to build projects in which there are unresolved compilation problems.
The main purpose is package and deploy or run aplications using some kind of stubs for classes that contains compilation errors, like I understand that Eclipse does (thanks to JDT Core).
I configurate maven java compiler plugin following Apache Maven documentation at Using Non-Javac compiler to use Eclipse compiler. Thinking that maybe should set some arguments to modify the compiler/builder behaivor I was reading Help Eclipse - Compiling Java code but I don't realize which compiler/builder option or combination of these does the trick.
So far, the next configuration of the maven java compiler plugins compile using the eclipse compiler and package the application including generated .class (jvm bytecode) only for java classes without compilation errors. To get this behaivor it just require use the eclipse compiler (see compilerId and the dependency) and set failOnError=false.
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<compilerId>eclipse</compilerId>
<source>1.7</source>
<target>1.7</target>
<optimize>true</optimize>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
<failOnError>false</failOnError>
<compilerArguments>
<org.eclipse.jdt.core.compiler.problem.fatalOptionalError>disabled</org.eclipse.jdt.core.compiler.problem.fatalOptionalError>
<org.eclipse.jdt.core.compiler.problem.forbiddenReference>ignore</org.eclipse.jdt.core.compiler.problem.forbiddenReference>
</compilerArguments>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-eclipse</artifactId>
<version>2.3</version>
</dependency>
</dependencies>
</plugin>
With this configuration I could run java application as long as the execution doesn't use classes not included for compilation errors (because the stubs aren't generated) but on a Java EE container, the classloading will faild so the application can never be deployed.
I appreciate any help on this.
Just for share the solution, at that moment I just replace the plexus-compiler-eclipse with tycho-compiler-jdt to get the desire behaivor.
The proceedOnError parameter indicates that it must keep compiling in spite of errors, dumping class files with problem methods or problem types how to deal with the compilation errors.
Next is the final configuration sample.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<compilerId>jdt</compilerId>
<source>1.7</source>
<target>1.7</target>
<optimize>true</optimize>
<failOnError>false</failOnError>
<compilerArguments>
<proceedOnError/>
</compilerArguments>
</configuration>
<dependencies>
<dependency>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-compiler-jdt</artifactId>
<version>0.22.0</version>
</dependency>
</dependencies>
</plugin>
There is more plugin configuration examples in the Tycho FAQ.
And the possible compiler arguments are described in section Using the batch compiler of the Java development user guide (Eclipse Help site).
Related
Maven is a powerful build tool for Java software projects.
I was reading about Maven plugins. (maven-compiler-plugin)_
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
For any project to run using maven, it definitely need to compile the code.
But i can see many sample projects online which doesn't have this plugin and still work.
Can anybody explain what is the difference in this plugin and by default compiling?
If you do nothing, Maven will call the maven compiler plugin which is called in the maven default lifecycle.
If you want to change the configuration, you need to add the plugin to <plugins> and then change the configuration. Often people do this to change the Java version (which can also be done through properties) or to fix the version of the plugin (instead of always using the latest version).
I am deploying webapp to the openshift cloud.
While compiling the resources by maven automatically after deploying, it shows Base64: symbol not found
However when I maven compile it on my Pc, their are no errors and build is successfull. I tried to change Base64 from java.util to apache.commons.codecs. The error is still there while deploying and it successfully runs at my local machine
Following is the pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
<dependencies>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.4</version>
</dependency>
Should I place the commons-codec jar in WEB_INF directory. i read the solution somewhere but was not sure about it.
please suggest a solution. Thank you
</dependencies>
My guess is that you're using JDK 8 on your machine, but JDK 7 where the error is happening as java.util.Base64 is only available since Java SE 8.
I recommend to use the same Java version on both machines.
Otherwise you should consider cross-compiling. Just setting the source and target level is not enough, as you can see, as you're still able to call new APIs.
In the Eclipse Compiler for Java standalone, I am able to log in XML the compilation info via a command-line atribute, as in this stub:
java -jar ecj-4.3.2.jar -log compile.xml <classpath,files>
However, when I use maven-compiler-plugin with plexus-compiler-eclipse, it seems I am unable to pass this argument to the compiler, and I am not sure the cause of this, whether the plugin's compiler is another one, it doesn't spawn new processes (i even tried the executable parameter), or other reason.
Here is the pom.xml section:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<compilerId>eclipse</compilerId>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
<!--<compilerArgument> -log compile.xml </compilerArgument>-->
<compilerArgs>
<arg>-log</arg>
<arg>compile.xml</arg>
</compilerArgs>
<fork>true</fork>
<verbose>true</verbose>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-eclipse</artifactId>
<version>2.3</version>
</dependency>
</dependencies>
</plugin>
The eclipse implementation is plexus-compiler-eclipse, it doesn't accept fork argument, as it uses the internal jvm. So, it can only accept jvm options like MAVEN_OPTS.
However, the default implementation is plexus-compiler-javac, which supports custom executable. The workaround may like this: set fork to true, and specify the executable.
For wraper in bash, you can visit here: https://stackoverflow.com/a/37971000/3289354
I am using maven profiles to switch between two "setups" in Intelli J. How can I switch the bytecode target level? That is: I want to change the following setting in compiler.xml
<bytecodeTargetLevel>
<module name="finmath-lib" target="1.6" />
</bytecodeTargetLevel>
Note: I tried to perform this via the following part in the respective Maven 3 profile
<profile>
<id>java-8</id>
<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>
</profile>
but this does not work!
Note: The pom.xml etc. belongs to the finmath lib project, and if you are interested, it can be found at www.finmath.net
I am using IntelliJ IDEA 14.1.3 and it works with following config ...
<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>
Hope this is helpful. Thanks!
The problem is that you want to change it to 1.8.
I've tried to switch IntelliJ's compiler version between 1.7 and 1.6 or 1.5 using Maven profile successfully.
However when you want to change it to 1.8, the config will be ignored.
I don't know whether this is maven's problem or Intellj's.
It seems that the JDK 1.8 is not well supported now, which is understandable.
You can open the Maven Projects tool window in IntelliJ and select the profile you want to use from the list.
In IntelliJ 13, File > Project Structure, set the Project language level to 8.0.
Since I had some problems using cobertura with Java 7 - I'm trying Jacoco.
My project has a parent pom.xml and sub projects.
In one project I use spring to run some integration tests - so I have this plugin in this project's pom.xml:
<plugin>
<version>2.12.4</version>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- -XX:-UseSplitVerifier is for java 7 -->
<argLine>
-XX:-UseSplitVerifier
-javaagent:${settings.localRepository}/org/springframework/spring-instrument/${spring.version}/spring-instrument-${spring.version}.jar
</argLine>
</configuration>
</plugin>
Since I use Java 7, I've set this plugin in the parent pom.xml:
<plugin>
<version>2.5.1</version>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<optimize>true</optimize>
<debug>true</debug>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<encoding>utf8</encoding>
</configuration>
</plugin>
Now, when I'm using mvn clean install all the projects have this file in the /target folder: jacoco.exec
; But this project that uses the spring-instrument does not have this file.
I think the problem is that Jacoco wishes to use the asm of spring-instrument but it fails (but I'm not sure I'm right).
The Jacoco version is 0.6.3.201306030806.
Why does Jacoco fails to instrument in this case?
How can I overcome this?
I thought maybe I can configure the maven-compiler-plugin to compile the code to 1.6 and then I wouldn't need the maven-surefire-plugin plugin. Does it make sense?
The argLine value defined by Jacoco Maven Plugin is being rewritten by the Surefire Plugin.
Set a property name in your "jacoco-maven-plugin" configuration like this:
<propertyName>coverageAgent</propertyName>
and then edit the argLine in your surefire plugin configuration so it includes Jacoco's agent:
<argLine>
-XX:-UseSplitVerifier
${coverageAgent}
-javaagent:${settings.localRepository}/org/springframework/spring-instrument/${spring.version}/spring-instrument-${spring.version}.jar
</argLine>
Notice that the Jacoco's agent is placed before the Spring's Instrument. That's the way it should be done because Jacoco has problems dealing with modified bytecode (e.g. the one produced by AspectJ LTW).
Actually, even when being the first agent, Jacoco's reports can still be wrong, but the problem is usually limited to a small set of circumstances (e.g. http://sourceforge.net/p/eclemma/discussion/614869/thread/3d875388 ).
my guess is that JaCoCo also uses the java command line, as it is probably implemented as a javaagent.
could it be that the spring-instrument javaagent overrides the JaCoCo one ?