View Javadoc
1   package org.codehaus.gmavenplus.mojo;
2   
3   import org.apache.maven.artifact.DependencyResolutionRequiredException;
4   import org.apache.maven.plugin.MojoExecutionException;
5   import org.apache.maven.plugins.annotations.LifecyclePhase;
6   import org.apache.maven.plugins.annotations.Mojo;
7   import org.apache.maven.plugins.annotations.Parameter;
8   import org.apache.maven.plugins.annotations.ResolutionScope;
9   import org.apache.maven.shared.model.fileset.FileSet;
10  
11  import java.io.File;
12  import java.lang.reflect.InvocationTargetException;
13  import java.net.MalformedURLException;
14  
15  
16  /**
17   * Compiles the main sources.
18   * Note that this mojo requires Groovy >= 1.5.0, and >= 2.0.0-beta-3 (the indy version) for compiling with invokedynamic option.
19   *
20   * @author Keegan Witt
21   * @since 1.0-beta-1
22   */
23  @Mojo(name = "compile", defaultPhase = LifecyclePhase.COMPILE, requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = true)
24  public class CompileMojo extends AbstractCompileMojo {
25  
26      /**
27       * The Groovy source files (relative paths).
28       * Default: "${project.basedir}/src/main/groovy/**/*.groovy"
29       */
30      @Parameter
31      protected FileSet[] sources;
32  
33      /**
34       * The location for the compiled classes.
35       */
36      @Parameter(defaultValue = "${project.build.outputDirectory}")
37      protected File outputDirectory;
38  
39      /**
40       * Executes this mojo.
41       *
42       * @throws MojoExecutionException If an unexpected problem occurs (causes a "BUILD ERROR" message to be displayed)
43       */
44      @Override
45      public void execute() throws MojoExecutionException {
46          try {
47              try {
48                  getLog().debug("Project compile classpath:\n" + project.getCompileClasspathElements());
49              } catch (DependencyResolutionRequiredException e) {
50                  getLog().debug("Unable to log project compile classpath");
51              }
52              doCompile(getFiles(sources, false), project.getCompileClasspathElements(), outputDirectory);
53          } catch (ClassNotFoundException e) {
54              throw new MojoExecutionException("Unable to get a Groovy class from classpath (" + e.getMessage() + "). Do you have Groovy as a compile dependency in your project?", e);
55          } catch (InvocationTargetException e) {
56              throw new MojoExecutionException("Error occurred while calling a method on a Groovy class from classpath.", e);
57          } catch (InstantiationException e) {
58              throw new MojoExecutionException("Error occurred while instantiating a Groovy class from classpath.", e);
59          } catch (IllegalAccessException e) {
60              throw new MojoExecutionException("Unable to access a method on a Groovy class from classpath.", e);
61          } catch (DependencyResolutionRequiredException e) {
62              throw new MojoExecutionException("Compile dependencies weren't resolved.", e);
63          } catch (MalformedURLException e) {
64              throw new MojoExecutionException("Unable to add project compile dependencies to classpath.", e);
65          }
66      }
67  
68  }