Java Reference
In-Depth Information
This will cause Maven to go through the clean phase and invoke all of the plug-ins
that are attached to this phase, in particular the maven-clean-plugin , which will
delete the target/ directory, where our generated site resides.
10.3.1
Maven Compiler plug-in
Like any other build system, Maven is supposed to build your projects—compile your
software and package in an archive. As we mentioned at the beginning of the chapter,
every task in Maven in done by an appropriate plug-in, the configuration of which
happens in the <plugins> section of our project descriptor. To compile your source
code, all you need to do is invoke the compile phase on the command line:
mvn compile
This will cause Maven to execute all of the plug-ins that are attached to the compile
phase (in particular it will invoke the maven-compiler-plugin ). But before invok-
ing the compile phase, as already discussed, Maven will go through the validate
phase and will download all of the dependencies that are listed in the pom.xml and
include them in the classpath of the project. Once the compilation process is com-
pleted, you can go to the target/classes/ directory, and you should see the compiled
classes there.
Let's move on and try to configure the Compiler plug-in. Notice the italics in
the previous sentence? Yeah, that's right—we'll escape from the convention-over-
configuration principle and will try to configure the Compiler plug-in.
So far, we've used the conventional Compiler plug-in, and everything worked well.
But what if we need to include the -source and -target attributes in the compiler
invocation to generate class files for a specific version of the JVM? We should add the
lines in listing 10.7 to the <build> section of our buildfile.
Listing 10.7
Configuring the maven-compiler-plugin
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.4</source>
<target>1.4</target>
</configuration>
</plugin>
</plugins>
</build>
This is a general way to configure each one of your Maven plug-ins; you enter a
<plugins> section into your <build> section. There you list each of the plug-ins that
you want to configure. In our case, it's the maven-compiler-plugin . You need to
enter the configuration parameters in the plug-in's configuration section. You can
get a list of parameters for every plug-in from the Maven website.
 
 
 
 
 
 
Search WWH ::




Custom Search