Skip to content

Commit

Permalink
Add support for Groovy 4
Browse files Browse the repository at this point in the history
Closes gh-1312
  • Loading branch information
snicoll committed Apr 27, 2022
1 parent 443d167 commit 6bbdc60
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,9 +28,16 @@
*/
class GroovyDependenciesConfigurer implements BuildCustomizer<Build> {

private final boolean isUsingGroovy4;

GroovyDependenciesConfigurer(boolean isUsingGroovy4) {
this.isUsingGroovy4 = isUsingGroovy4;
}

@Override
public void customize(Build build) {
build.dependencies().add("groovy", "org.codehaus.groovy", "groovy", DependencyScope.COMPILE);
String groupId = this.isUsingGroovy4 ? "org.apache.groovy" : "org.codehaus.groovy";
build.dependencies().add("groovy", groupId, "groovy", DependencyScope.COMPILE);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,6 +36,8 @@
import io.spring.initializr.generator.spring.code.MainApplicationTypeCustomizer;
import io.spring.initializr.generator.spring.code.ServletInitializerCustomizer;
import io.spring.initializr.generator.spring.code.TestApplicationTypeCustomizer;
import io.spring.initializr.generator.version.VersionParser;
import io.spring.initializr.generator.version.VersionRange;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -49,6 +51,8 @@
@Configuration
class GroovyProjectGenerationDefaultContributorsConfiguration {

private static final VersionRange GROOVY4 = VersionParser.DEFAULT.parseRange("3.0.0-M2");

@Bean
MainApplicationTypeCustomizer<GroovyTypeDeclaration> mainMethodContributor() {
return (typeDeclaration) -> typeDeclaration.addMethodDeclaration(
Expand All @@ -69,8 +73,8 @@ TestApplicationTypeCustomizer<GroovyTypeDeclaration> junitJupiterTestMethodContr
}

@Bean
BuildCustomizer<Build> groovyDependenciesConfigurer() {
return new GroovyDependenciesConfigurer();
BuildCustomizer<Build> groovyDependenciesConfigurer(ProjectDescription description) {
return new GroovyDependenciesConfigurer(GROOVY4.match(description.getPlatformVersion()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -87,6 +87,17 @@ private void testCurrentGenerationJar(Language language, BuildSystem build, Stri
new ClassPathResource("project/" + language + "/standard/" + getAssertFileName(fileName)));
}

@ParameterizedTest
@MethodSource("parameters")
void nextGenerationJarGroovy(BuildSystem build, String fileName) {
testNextGenerationJar(new GroovyLanguage("17"), build, fileName);
}

private void testNextGenerationJar(Language language, BuildSystem build, String fileName) {
assertThat(generateProject(language, build, "3.0.0")).textFile(fileName).hasSameContentAs(
new ClassPathResource("project/" + language + "/next/" + getAssertFileName(fileName)));
}

@ParameterizedTest
@MethodSource("parameters")
void currentGenerationWarJava(BuildSystem build, String fileName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
plugins {
id 'org.springframework.boot' version '3.0.0'
id 'io.spring.dependency-management' version '1.0.6.RELEASE'
id 'groovy'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

repositories {
mavenCentral()
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.apache.groovy:groovy'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

tasks.named('test') {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
plugins {
id("org.springframework.boot") version "3.0.0"
id("io.spring.dependency-management") version "1.0.6.RELEASE"
groovy
}

group = "com.example"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17

repositories {
mavenCentral()
}

dependencies {
implementation("org.springframework.boot:spring-boot-starter")
implementation("org.apache.groovy:groovy")
testImplementation("org.springframework.boot:spring-boot-starter-test")
}

tasks.withType<Test> {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.13.1</version>
<executions>
<execution>
<goals>
<goal>addSources</goal>
<goal>addTestSources</goal>
<goal>generateStubs</goal>
<goal>compile</goal>
<goal>generateTestStubs</goal>
<goal>compileTests</goal>
<goal>removeStubs</goal>
<goal>removeTestStubs</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>

0 comments on commit 6bbdc60

Please sign in to comment.