mirror of
https://gitee.com/dcren/initializr.git
synced 2025-12-27 06:35:51 +08:00
Upgrade to GMavenPlus
A groovy-based project using Maven now builds with GMavenPlus as the Groovy Eclipse maven compiler does not seem to be maintained anymore. This commit also harmonizes the location of the code to be `src/main/groovy` for both Gradle and Maven builds. Joint compilation is enabled by default so that you can create pure Java code in `src/main/java` and refer to any class within the project. Users of IntelliJ IDEA may want to install a plugin that automatically adds `src/main/groovy` to the sources when the GMavenPlus plugin is added to the pom, see https://plugins.jetbrains.com/plugin/7442 Closes gh-90
This commit is contained in:
@@ -102,7 +102,7 @@ class ProjectGenerator {
|
||||
def applicationName = request.applicationName
|
||||
def language = request.language
|
||||
|
||||
String codeLocation = ((language.equals("groovy") && gradleBuild) ? 'groovy': 'java')
|
||||
String codeLocation = language.equals("groovy") ? 'groovy': 'java'
|
||||
def src = new File(new File(dir, "src/main/$codeLocation"), request.packageName.replace('.', '/'))
|
||||
src.mkdirs()
|
||||
write(new File(src, "${applicationName}.${language}"), "Application.$language", model)
|
||||
|
||||
@@ -78,28 +78,23 @@
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin><% if (language=='groovy') { %>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<compilerId>groovy-eclipse-compiler</compilerId>
|
||||
</configuration>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy-eclipse-compiler</artifactId>
|
||||
<version>2.9.1-01</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy-eclipse-batch</artifactId>
|
||||
<version>2.3.7-01</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy-eclipse-compiler</artifactId>
|
||||
<version>2.9.1-01</version>
|
||||
<extensions>true</extensions>
|
||||
<groupId>org.codehaus.gmavenplus</groupId>
|
||||
<artifactId>gmavenplus-plugin</artifactId>
|
||||
<version>1.5</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>addSources</goal>
|
||||
<goal>addTestSources</goal>
|
||||
<goal>generateStubs</goal>
|
||||
<goal>compile</goal>
|
||||
<goal>testGenerateStubs</goal>
|
||||
<goal>testCompile</goal>
|
||||
<goal>removeStubs</goal>
|
||||
<goal>removeTestStubs</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin><% } %>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
@@ -217,7 +217,7 @@ class ProjectGeneratorTests {
|
||||
request.bootVersion = '1.1.9.RELEASE'
|
||||
request.name = 'MyDemo'
|
||||
request.packageName = 'foo'
|
||||
generateProject(request).sourceCodeAssert('src/main/java/foo/MyDemoApplication.groovy')
|
||||
generateProject(request).sourceCodeAssert('src/main/groovy/foo/MyDemoApplication.groovy')
|
||||
.hasImports(EnableAutoConfiguration.class.name, ComponentScan.class.name, Configuration.class.name)
|
||||
.doesNotHaveImports(SpringBootApplication.class.name)
|
||||
.contains('@EnableAutoConfiguration', '@Configuration', '@ComponentScan')
|
||||
@@ -231,7 +231,7 @@ class ProjectGeneratorTests {
|
||||
request.bootVersion = '1.2.0.RC1'
|
||||
request.name = 'MyDemo'
|
||||
request.packageName = 'foo'
|
||||
generateProject(request).sourceCodeAssert('src/main/java/foo/MyDemoApplication.groovy')
|
||||
generateProject(request).sourceCodeAssert('src/main/groovy/foo/MyDemoApplication.groovy')
|
||||
.hasImports(SpringBootApplication.class.name)
|
||||
.doesNotHaveImports(EnableAutoConfiguration.class.name, ComponentScan.class.name, Configuration.class.name)
|
||||
.contains('@SpringBootApplication')
|
||||
@@ -257,7 +257,7 @@ class ProjectGeneratorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void groovyWithMavenUsesJavaDir() {
|
||||
void groovyWithMavenUsesGroovyDir() {
|
||||
def request = createProjectRequest('web')
|
||||
request.type = 'maven-project'
|
||||
request.language = 'groovy'
|
||||
|
||||
@@ -109,10 +109,9 @@ class ProjectAssert {
|
||||
}
|
||||
|
||||
ProjectAssert isGroovyProject(String expectedPackageName, String expectedApplicationName) {
|
||||
String codeLocation = (mavenProject ? 'java' : 'groovy')
|
||||
String packageName = expectedPackageName.replace('.', '/')
|
||||
hasFile("src/main/$codeLocation/$packageName/${expectedApplicationName}.groovy",
|
||||
"src/test/$codeLocation/$packageName/${expectedApplicationName}Tests.groovy",
|
||||
hasFile("src/main/groovy/$packageName/${expectedApplicationName}.groovy",
|
||||
"src/test/groovy/$packageName/${expectedApplicationName}Tests.groovy",
|
||||
'src/main/resources/application.properties')
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user