Support using the Maven plugin to generate test sources

Fixes #1579
This commit is contained in:
Sam Harwell 2017-01-07 10:58:43 -06:00
parent 33ac0c3611
commit 5d4efafe8e
2 changed files with 16 additions and 2 deletions

View File

@ -150,6 +150,13 @@ public class Antlr4Mojo extends AbstractMojo {
@Parameter(property = "project", required = true, readonly = true)
protected MavenProject project;
/**
* Specifies whether sources are added to the {@code compile} or
* {@code test} scope.
*/
@Parameter(property = "antlr4.generateTestSources", defaultValue = "false")
private boolean generateTestSources;
/**
* The directory where the ANTLR grammar files ({@code *.g4}) are located.
*/
@ -190,7 +197,12 @@ public class Antlr4Mojo extends AbstractMojo {
}
void addSourceRoot(File outputDir) {
project.addCompileSourceRoot(outputDir.getPath());
if (generateTestSources) {
project.addTestCompileSourceRoot(outputDir.getPath());
}
else {
project.addCompileSourceRoot(outputDir.getPath());
}
}
/**

View File

@ -39,7 +39,7 @@
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
@ -129,7 +129,9 @@
</goals>
<configuration>
<sourceDirectory>${basedir}/test</sourceDirectory>
<outputDirectory>${project.build.directory}/generated-test-sources/antlr4</outputDirectory>
<visitor>true</visitor>
<generateTestSources>true</generateTestSources>
</configuration>
</execution>
</executions>