Maven: use maven-annotations in kotlin-maven-plugin

This commit is contained in:
Sergey Mashkov
2015-05-18 16:32:11 +03:00
parent 35ed682714
commit d04ec74217
5 changed files with 34 additions and 65 deletions
+1 -1
View File
@@ -61,7 +61,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId> <artifactId>maven-plugin-plugin</artifactId>
<version>2.9</version> <version>3.1</version>
</plugin> </plugin>
</plugins> </plugins>
@@ -22,6 +22,10 @@ import com.sampullara.cli.Args;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log; import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments; import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments;
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler; import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler;
@@ -42,40 +46,29 @@ import static com.intellij.openapi.util.text.StringUtil.join;
/** /**
* Compiles kotlin sources * Compiles kotlin sources
* *
* @goal compile
* @phase compile
* @requiresDependencyResolution compile
* @noinspection UnusedDeclaration * @noinspection UnusedDeclaration
*/ */
@Mojo(name = "compile", defaultPhase = LifecyclePhase.COMPILE, requiresDependencyResolution = ResolutionScope.COMPILE)
public class K2JVMCompileMojo extends KotlinCompileMojoBase<K2JVMCompilerArguments> { public class K2JVMCompileMojo extends KotlinCompileMojoBase<K2JVMCompilerArguments> {
/** /**
* The directories used to scan for annotation.xml files for Kotlin annotations * The directories used to scan for annotation.xml files for Kotlin annotations
*
* @parameter
*/ */
@Parameter
public List<String> annotationPaths; public List<String> annotationPaths;
/** @Parameter(defaultValue = "true")
* @parameter default-value="true"
*/
public boolean scanForAnnotations; public boolean scanForAnnotations;
/** /**
* Project classpath. * Project classpath.
*
* @parameter default-value="${project.compileClasspathElements}"
* @required
* @readonly
*/ */
@Parameter(defaultValue = "${project.compileClasspathElements}", required = true, readonly = true)
public List<String> classpath; public List<String> classpath;
/** /**
* Project test classpath. * Project test classpath.
*
* @parameter default-value="${project.testClasspathElements}"
* @required
* @readonly
*/ */
@Parameter(defaultValue = "${project.testClasspathElements}", required = true, readonly = true)
protected List<String> testClasspath; protected List<String> testClasspath;
@NotNull @NotNull
@@ -22,6 +22,7 @@ import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log; import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.cli.common.CLICompiler; import org.jetbrains.kotlin.cli.common.CLICompiler;
@@ -47,17 +48,14 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
/** /**
* The default source directories containing the sources to be compiled. * The default source directories containing the sources to be compiled.
*
* @parameter default-value="${project.compileSourceRoots}"
* @required
*/ */
@Parameter(defaultValue = "${project.compileSourceRoots}", required = true)
private List<String> defaultSourceDirs; private List<String> defaultSourceDirs;
/** /**
* The source directories containing the sources to be compiled. * The source directories containing the sources to be compiled.
*
* @parameter
*/ */
@Parameter
private List<String> sourceDirs; private List<String> sourceDirs;
public List<String> getSources() { public List<String> getSources() {
@@ -67,58 +65,41 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
/** /**
* Suppress all warnings. * Suppress all warnings.
*
* @parameter default-value="false"
*/ */
@Parameter(defaultValue = "false")
public boolean nowarn; public boolean nowarn;
// TODO not sure why this doesn't work :( @Parameter(defaultValue = "${project}", required = true, readonly = true)
// * @parameter default-value="$(project.basedir}/src/main/resources"
/**
* @parameter default-value="${project}"
* @required
* @readonly
*/
public MavenProject project; public MavenProject project;
/** /**
* The directory for compiled classes. * The directory for compiled classes.
*
* @parameter default-value="${project.build.outputDirectory}"
* @required
* @readonly
*/ */
@Parameter(defaultValue = "${project.build.outputDirectory}", required = true, readonly = true)
public String output; public String output;
/** /**
* The directory for compiled tests classes. * The directory for compiled tests classes.
*
* @parameter default-value="${project.build.testOutputDirectory}"
* @required
* @readonly
*/ */
@Parameter(defaultValue = "${project.build.testOutputDirectory}", required = true, readonly = true)
public String testOutput; public String testOutput;
/** /**
* Kotlin compilation module, as alternative to source files or folders. * Kotlin compilation module, as alternative to source files or folders.
*
* @parameter
*/ */
@Parameter
public String module; public String module;
/** /**
* Kotlin compilation module, as alternative to source files or folders (for tests). * Kotlin compilation module, as alternative to source files or folders (for tests).
*
* @parameter
*/ */
@Parameter
public String testModule; public String testModule;
/** /**
* Additional command line arguments for Kotlin compiler. * Additional command line arguments for Kotlin compiler.
*
* @parameter
*/ */
@Parameter
public List<String> args; public List<String> args;
protected final Log LOG = getLog(); protected final Log LOG = getLog();
@@ -18,6 +18,10 @@ package org.jetbrains.kotlin.maven;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments; import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments;
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler; import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler;
@@ -27,18 +31,17 @@ import java.util.List;
/** /**
* Compiles Kotlin test sources * Compiles Kotlin test sources
* *
* @goal test-compile
* @phase test-compile
* @requiresDependencyResolution test
* @noinspection UnusedDeclaration * @noinspection UnusedDeclaration
*/ */
@Mojo(name = "test-compile",
defaultPhase = LifecyclePhase.TEST_COMPILE,
requiresDependencyResolution = ResolutionScope.TEST
)
public class KotlinTestCompileMojo extends K2JVMCompileMojo { public class KotlinTestCompileMojo extends K2JVMCompileMojo {
/** /**
* Flag to allow test compilation to be skipped. * Flag to allow test compilation to be skipped.
*
* @parameter expression="${maven.test.skip}" default-value="false"
* @noinspection UnusedDeclaration
*/ */
@Parameter(property = "maven.test.skip", defaultValue = "false")
private boolean skip; private boolean skip;
// TODO it would be nice to avoid using 2 injected fields for sources // TODO it would be nice to avoid using 2 injected fields for sources
@@ -48,17 +51,14 @@ public class KotlinTestCompileMojo extends K2JVMCompileMojo {
/** /**
* The default source directories containing the sources to be compiled. * The default source directories containing the sources to be compiled.
*
* @parameter default-value="${project.testCompileSourceRoots}"
* @required
*/ */
@Parameter(defaultValue = "${project.testCompileSourceRoots}", required = true)
private List<String> defaultSourceDirs; private List<String> defaultSourceDirs;
/** /**
* The source directories containing the sources to be compiled. * The source directories containing the sources to be compiled.
*
* @parameter
*/ */
@Parameter
private List<String> sourceDirs; private List<String> sourceDirs;
@Override @Override
@@ -69,19 +69,15 @@ public class KotlinTestCompileMojo extends K2JVMCompileMojo {
/** /**
* The source directories containing the sources to be compiled for tests. * The source directories containing the sources to be compiled for tests.
*
* @parameter default-value="${project.testCompileSourceRoots}"
* @required
* @readonly
*/ */
@Parameter(defaultValue = "${project.testCompileSourceRoots}", required = true, readonly = true)
private List<String> defaultSourceDir; private List<String> defaultSourceDir;
@Override @Override
public void execute() throws MojoExecutionException, MojoFailureException { public void execute() throws MojoExecutionException, MojoFailureException {
if (skip) { if (skip) {
getLog().info("Test compilation is skipped"); getLog().info("Test compilation is skipped");
} } else {
else {
super.execute(); super.execute();
} }
} }
@@ -97,8 +97,7 @@ public class KotlinTestJSCompilerMojo extends K2JSCompilerMojo {
public void execute() throws MojoExecutionException, MojoFailureException { public void execute() throws MojoExecutionException, MojoFailureException {
if (skip) { if (skip) {
getLog().info("Test compilation is skipped"); getLog().info("Test compilation is skipped");
} } else {
else {
super.execute(); super.execute();
} }
} }