From a1ab5763c7131263b852a3547b58b29434c3c386 Mon Sep 17 00:00:00 2001 From: PatrickWalter214 Date: Tue, 24 Sep 2024 12:02:06 +0200 Subject: [PATCH] Add support for Spring Boot Gradle plugin using plugins DSL --- .../gradle/tasks/AbstractLibertyTask.groovy | 4 ++- .../gradle/TestSpringBootApplication30.groovy | 16 ++++++++++++ .../sample.springboot3/settings.gradle | 10 +++++++- ...est_spring_boot_plugins_dsl_apps_30.gradle | 25 +++++++++++++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 src/test/resources/sample.springboot3/test_spring_boot_plugins_dsl_apps_30.gradle diff --git a/src/main/groovy/io/openliberty/tools/gradle/tasks/AbstractLibertyTask.groovy b/src/main/groovy/io/openliberty/tools/gradle/tasks/AbstractLibertyTask.groovy index 5f7d164d5..8d1deb6e0 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/tasks/AbstractLibertyTask.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/tasks/AbstractLibertyTask.groovy @@ -80,7 +80,9 @@ abstract class AbstractLibertyTask extends DefaultTask { if (project.plugins.hasPlugin("org.springframework.boot")) { try { for (Dependency dep : project.buildscript.configurations.classpath.getAllDependencies().toArray()) { - if ("org.springframework.boot".equals(dep.getGroup()) && "spring-boot-gradle-plugin".equals(dep.getName())) { + if ("org.springframework.boot".equals(dep.getGroup()) && + ("spring-boot-gradle-plugin".equals(dep.getName()) || + "org.springframework.boot.gradle.plugin".equals(dep.getName()))) { version = dep.getVersion() break } diff --git a/src/test/groovy/io/openliberty/tools/gradle/TestSpringBootApplication30.groovy b/src/test/groovy/io/openliberty/tools/gradle/TestSpringBootApplication30.groovy index fe1ba5dcd..1c8791ed2 100644 --- a/src/test/groovy/io/openliberty/tools/gradle/TestSpringBootApplication30.groovy +++ b/src/test/groovy/io/openliberty/tools/gradle/TestSpringBootApplication30.groovy @@ -132,4 +132,20 @@ public class TestSpringBootApplication30 extends AbstractIntegrationTest{ throw new AssertionError ("Fail on task deploy.", e) } } + + @Test + public void test_spring_boot_plugins_dsl_apps_30() { + try { + runTasks(buildDir, 'deploy', 'libertyStart') + + String webPage = new URL("http://localhost:9080").getText() + Assert.assertEquals("Did not get expected http response.","Hello!", webPage) + Assert.assertTrue('defaultServer/dropins has app deployed', + new File(buildDir, 'build/wlp/usr/servers/defaultServer/dropins').list().size() == 0) + Assert.assertTrue('no app in apps folder', + new File(buildDir, "build/wlp/usr/servers/defaultServer/apps/thin-${testName.getMethodName()}-1.0-SNAPSHOT.jar").exists() ) + } catch (Exception e) { + throw new AssertionError ("Fail on task deploy.", e) + } + } } diff --git a/src/test/resources/sample.springboot3/settings.gradle b/src/test/resources/sample.springboot3/settings.gradle index c2d3edc19..e05832444 100644 --- a/src/test/resources/sample.springboot3/settings.gradle +++ b/src/test/resources/sample.springboot3/settings.gradle @@ -1 +1,9 @@ -//Empty \ No newline at end of file +pluginManagement { + repositories { + mavenCentral() + mavenLocal() + maven { + url = uri(file("$rootDir/../../plugin-test-repository/")) + } + } +} \ No newline at end of file diff --git a/src/test/resources/sample.springboot3/test_spring_boot_plugins_dsl_apps_30.gradle b/src/test/resources/sample.springboot3/test_spring_boot_plugins_dsl_apps_30.gradle new file mode 100644 index 000000000..c6e15a99f --- /dev/null +++ b/src/test/resources/sample.springboot3/test_spring_boot_plugins_dsl_apps_30.gradle @@ -0,0 +1,25 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '3.1.3' + id 'io.spring.dependency-management' version '1.1.6' + id 'io.openliberty.tools.gradle.Liberty' version "$lgpVersion" +} + +group = 'liberty.gradle' +version = '1.0-SNAPSHOT' +sourceCompatibility = 17 + +repositories { + mavenCentral() +} +dependencies { + implementation("org.springframework.boot:spring-boot-starter-web") + testImplementation('org.springframework.boot:spring-boot-starter-test') + libertyRuntime group: 'io.openliberty', name: 'openliberty-runtime', version: '23.0.0.10' +} + +liberty { + server { + serverXmlFile = file("src/main/liberty/config/server30.xml") + } +} \ No newline at end of file