Skip to content

Commit

Permalink
Add Convention Plugins for Spring Boot
Browse files Browse the repository at this point in the history
  • Loading branch information
jjohannes committed Nov 6, 2024
1 parent 766b36f commit 0bfa00c
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 56 deletions.
8 changes: 5 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
plugins { id("org.example.gradle.component.application") }

application { mainClass = "org.example.product.app.Application" }

dependencies {
implementation(projects.bespin)
implementation(projects.corellia)
Expand All @@ -12,8 +10,12 @@ dependencies {
implementation(libs.guice)
implementation(libs.guice.servlet)
implementation(libs.slf4j.api)
implementation(libs.spring.boot)
implementation(libs.spring.boot.autoconfigure)
implementation(libs.spring.context)
implementation(libs.spring.web)
runtimeOnly(libs.slf4j.simple)
providedCompile(libs.jakarta.servlet.api)
runtimeOnly(libs.spring.boot.starter.web)

mockApiImplementation(projects.app)
mockApiImplementation(libs.guava)
Expand Down
30 changes: 16 additions & 14 deletions app/src/main/java/org/example/product/app/AppServlet.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package org.example.product.app;

import static java.util.Objects.requireNonNull;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStreamReader;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AppServlet {

@WebServlet("/check")
public class AppServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
res.setContentType("text/html");
PrintWriter pw = res.getWriter();
pw.println("<html><body>");
pw.println("App is running...");
pw.println("</body></html>");
pw.close();
@GetMapping("/")
public String index() throws IOException {
new MainModule().run();
String version = new BufferedReader(
new InputStreamReader(requireNonNull(AppServlet.class.getResourceAsStream("/version.txt"))))
.readLine();
return "<html><body>" + "App is running... !!!!" + "<br/>Version " + version + "</body></html>";
}
}
8 changes: 5 additions & 3 deletions app/src/main/java/org/example/product/app/Application.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.example.product.app;

import java.io.IOException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {

public static void main(String[] args) throws IOException {
new MainModule().run();
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
7 changes: 7 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ poi = "5.2.2"
resteasy = "4.7.6.Final"
slf4j = "1.7.36"
solrj = "7.7.3"
spring-boot = "2.7.18"
typesafeconfig = "0.1.0"
velocity = "2.3"
zookeeper = "3.8.0"
Expand Down Expand Up @@ -50,6 +51,12 @@ resteasy-jackson2-provider = { module = "org.jboss.resteasy:resteasy-jackson2-pr
slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }
slf4j-simple = { module = "org.slf4j:slf4j-simple", version.ref = "slf4j" }
solr-solrj = { module = "org.apache.solr:solr-solrj", version.ref = "solrj" }
spring-boot = { module = "org.springframework.boot:spring-boot" }
spring-boot-autoconfigure = { module = "org.springframework.boot:spring-boot-autoconfigure" }
spring-boot-dependencies = { module = "org.springframework.boot:spring-boot-dependencies", version.ref = "spring-boot" }
spring-boot-starter-web = { module = "org.springframework.boot:spring-boot-starter-web" }
spring-context = { module = "org.springframework:spring-context" }
spring-web = { module = "org.springframework:spring-web" }
typesafeconfig-guice = { module = "com.github.racc:typesafeconfig-guice", version.ref = "typesafeconfig" }
velocity-engine-core = { module = "org.apache.velocity:velocity-engine-core", version.ref = "velocity" }
zookeeper = { module = "org.apache.zookeeper:zookeeper", version.ref = "zookeeper" }
Expand Down
1 change: 1 addition & 0 deletions gradle/plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dependencies {
implementation("io.fuchs.gradle.classpath-collision-detector:classpath-collision-detector:1.0.0")
implementation("org.cyclonedx:cyclonedx-gradle-plugin:1.10.0")
implementation("org.gradlex:jvm-dependency-conflict-resolution:2.1.2")
implementation("org.springframework.boot:spring-boot-gradle-plugin:2.7.18")
}

testing.suites.named<JvmTestSuite>("test") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins { id("org.gradle.base") }

// Set the group required to refer to a Module "from outside".
// I.e., when it is published or used in Included Builds.
group = "org.example.product.java"
group = "org.example.product.spring"

// Set the version from 'version.txt'
version = providers.fileContents(isolated.rootProject.projectDirectory.file("gradle/version.txt")).asText.getOrElse("")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
plugins {
id("org.gradle.application")
id("org.gradle.java")
id("org.example.gradle.base.dependency-rules")
id("org.example.gradle.base.identity")
id("org.example.gradle.base.lifecycle")
id("org.example.gradle.check.dependencies")
id("org.example.gradle.check.format-gradle")
id("org.example.gradle.check.format-java")
id("org.example.gradle.feature.spring-boot")
id("org.example.gradle.feature.checksum")
id("org.example.gradle.feature.package-version-txt")
id("org.example.gradle.feature.compile-java")
id("org.example.gradle.feature.javadoc")
id("org.example.gradle.feature.test")
id("org.example.gradle.feature.test-end-to-end")
id("org.example.gradle.feature.war")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins { id("org.gradle.java") }

tasks.processResources { from(isolated.rootProject.projectDirectory.file("gradle/version.txt")) }
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
plugins {
id("org.gradle.java")
id("org.springframework.boot")
id("org.example.gradle.base.dependency-rules")
}

dependencies { developmentOnly("org.springframework.boot:spring-boot-devtools") }

configurations {
productionRuntimeClasspath {
extendsFrom(configurations["internal"])
shouldResolveConsistentlyWith(configurations["mainRuntimeClasspath"])
}
developmentOnly {
extendsFrom(configurations["internal"])
shouldResolveConsistentlyWith(configurations["mainRuntimeClasspath"])
}
}

This file was deleted.

4 changes: 4 additions & 0 deletions gradle/versions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ plugins {
id("org.example.gradle.check.format-gradle")
}

javaPlatform.allowDependencies()

dependencies { api(platform(libs.spring.boot.dependencies)) }

// Reject versions that should not be upgraded beyond a certain point.
// This makes Dependabot PR builds fail that attempt to update these.
dependencies.constraints {
Expand Down
3 changes: 0 additions & 3 deletions kamino/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ plugins {

dependencies {
api(projects.coruscant)
api(libs.resteasy.core)
implementation(libs.resteasy.guice)
implementation(libs.resteasy.jackson2.provider)

testImplementation(libs.junit.jupiter.api)
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
package org.example.product.kamino;

import org.example.product.coruscant.CoruscantModuleData;
import org.jboss.resteasy.plugins.guice.GuiceResteasyBootstrapServletContextListener;
import org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider;
import org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap;

/**
* I am published and therefore I have Javadoc!
*/
public class KaminoModule {

/**
* Bootstrap...
*/
public ResteasyBootstrap bootstrap;

/**
* Data...
*/
Expand All @@ -26,8 +18,6 @@ public class KaminoModule {
* @return all the important Classes
*/
public Class<?>[] info() {
return new Class<?>[] {
ResteasyBootstrap.class, ResteasyJackson2Provider.class, GuiceResteasyBootstrapServletContextListener.class
};
return new Class<?>[] {};
}
}

0 comments on commit 0bfa00c

Please sign in to comment.