lunes, 7 de marzo de 2011

Other useful Maven plugins (Part I)

Maven Compiler plugin 

The Compiler Plugin is used to compile the sources of your project. The default compiler is javac and is used to compile Java sources. Also note that at present the default source setting is 1.5 and the default target setting is 1.5, independently of the JDK you run Maven with.

Usage:
[<plugins>]
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
        <compilerVersion>${java-version}</compilerVersion>
        <source>${java-version}</source>
        <target>${java-version}</target>
        <encoding>${project.build.sourceEncoding}</encoding>
    </configuration>
</plugin>
[</plugins>]


Maven compiler settings:

compilerVersion: Version of the compiler to use, ex. "1.3", "1.5", if fork is set to true.
encoding: The -encoding argument for the Java compiler.
source: The -source argument for the Java compiler.
target: The -target argument for the Java compiler.

If source and target are equals, no room for error in what version should the compiler user to interpret your sources (source) and to create the binary (target). More information about -source and -target configuration over here.

More options about this plugin is over here.


Maven Resources plugin

The Resources Plugin handles the copying of project resources to the output directory. There are two different kinds of resources: main resources and test resources. The difference is that the main resources are the resources associated to the main source code while the test resources are associated to the test source code.

Thus, this allows the separation of resources for the main source code and its unit tests.

Starting with version 2.3 this plugin uses the Maven Filtering shared component for filtering resources.

[<plugins>]
<plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.2</version>
    <configuration>
        <encoding>${project.build.sourceEncoding}</encoding>
     </configuration>
</plugin>
[</plugins>]

encoding: The character encoding scheme to be applied when filtering resources.


Maven Source plugin

The Source Plugin creates a jar archive of the source files of the current project. The jar file is, by default, created in the project's target directory.

They will be uploaded to your maven dependencies repository in deploy phase, and will be downloaded if necessary afterward.

[<plugins>]
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
    <version>2.1.2</version>
    <executions>
        <execution>
            <goals>
                <goal>jar</goal>
            </goals>
         </execution>
    </executions>
</plugin>
[<plugins>]



Maven  Eclipse plugin

The Eclipse Plugin is used to generate Eclipse IDE files (*.classpath, *.wtpmodules and the .settings folder) for use with a project.

[<plugins>]
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-eclipse-plugin</artifactId>
    <version>2.8</version>
    <configuration>
        <downloadSources>true</downloadSources>
        <downloadJavadocs>true</downloadJavadocs>
    </configuration>
</plugin>
[<plugins>]

Maven Eclipse settings:

downloadJavadocs: Enables/disables the downloading of javadoc attachments. Defaults to false. When this flag is true remote repositories are checked for javadocs: in order to avoid repeated check for unavailable javadoc archives, a status cache is mantained. With versions 2.6+ of the plugin to reset this cache run mvn eclipse:remove-cache, or use the forceRecheck option with versions. With older versions delete the file mvn-eclipse-cache.properties in the target directory.

downloadSources: Enables/disables the downloading of source attachments. Defaults to false. When this flag is true remote repositories are checked for sources: in order to avoid repeated check for unavailable source archives, a status cache is mantained. With versions 2.6+ of the plugin to reset this cache run mvn eclipse:remove-cache, or use the forceRecheck option with versions. With older versions delete the file mvn-eclipse-cache.properties in the target directory.


These sources were uploaded by Maven Source Plugin ;)



There will be more soon, then we could talk about how to organize them all.

3 comentarios:

  1. I always love good tips that help with design and making life a bit easier. There are some here that are new to me and some I’m already using and love. Can’t wait to try a few. Thanks for sharing! wordpress whmcs integration

    ResponderEliminar
  2. I just found your blog because I was looking for a new plugin for my site. hanks for this information, now if I can find some information on how to set them up. awaz

    ResponderEliminar
  3. You're welcome.
    Please take everything with a pinch of salt, as it might be outdated.

    ResponderEliminar

Nota: solo los miembros de este blog pueden publicar comentarios.