Maven compiler Plugin: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=External= * http://maven.apache.org/plugins/maven-compiler-plugin =Internal= * Maven#Plugin =Adding <tt>rt.jar</tt> to the compilation classpath= <pre> <plugin>...")
 
 
(4 intermediate revisions by the same user not shown)
Line 5: Line 5:
=Internal=
=Internal=


* [[Maven#Plugin]]
* [[Maven#Plugin|Maven]]
 
=Configuration Example=
 
<pre>
plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.6.0</version>
</plugin>
</pre>


=Adding <tt>rt.jar</tt> to the compilation classpath=
=Adding <tt>rt.jar</tt> to the compilation classpath=
Line 19: Line 29:
     </configuration>
     </configuration>
</plugin>
</plugin>
}}}
</pre>


=Source File Encoding=
=Source File Encoding=
Line 37: Line 47:
     <groupId>org.apache.maven.plugins</groupId>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-compiler-plugin</artifactId>
     <artifactId>maven-compiler-plugin</artifactId>
    <version>3.6.0</version>
     <configuration>
     <configuration>
             <source>1.7</source>
             <source>1.7</source>

Latest revision as of 16:37, 11 January 2017

External

Internal

Configuration Example

plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.6.0</version>
</plugin>

Adding rt.jar to the compilation classpath

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <compilerArguments>
            <bootclasspath>${java.home}\lib\rt.jar</bootclasspath>
        </compilerArguments>
    </configuration>
</plugin>

Source File Encoding

If nothing is explicitly configured, the plugin does not configure the java compiler -encoding flag:

[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ northstar ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 291 source files to /Users/ovidiu/c063-Apple/src/mobileappsfoundation/northstar/target/test-classes

To configure a specific encoding to be passed to the compiler, you can configure the "encoding" parameter on the plugin, which specifies the the -encoding argument for the Java compiler:

<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-compiler-plugin</artifactId>
     <version>3.6.0</version>
     <configuration>
            <source>1.7</source>
            <target>1.7</target>
            <debug>true</debug>
            <encoding>UTF-8</encoding>
     </configuration>
</plugin>

If not explicitly specified in the plugin configuration, the default value passed to the compiler is ${project.build.sourceEncoding}, if defined, or otherwise the platform default value.