Skip to content

Commit

Permalink
feat: add JRE 8 support for spring webmvc
Browse files Browse the repository at this point in the history
  • Loading branch information
benny123tw committed Jun 17, 2024
1 parent f95c259 commit 8167835
Show file tree
Hide file tree
Showing 10 changed files with 512 additions and 1 deletion.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
[versions]
# JRE 8
jre8_springframework = "5.3.15"
jre8_springframework_boot = "2.6.3"
jre8_spring_dependency_management = "1.0.11.RELEASE"
jre8_jackson_core = "2.13.0"
jre8_javax_servlet = "4.0.1"
jre8_javax_servlet_jsp = "2.3.3"

# JRE 17
springframework = "6.1.8"
springframework_boot = "3.3.0"
spring_dependency_management = "1.1.5"
Expand All @@ -12,6 +21,17 @@ publish_maven_plugin = "0.28.0"
dokka = "1.9.20"

[libraries]
# JRE 8
jre8_spring_core = { module = "org.springframework:spring-core", version.ref = "jre8_springframework" }
jre8_spring_webmvc = { module = "org.springframework:spring-webmvc", version.ref = "jre8_springframework" }
jre8_spring_boot_starter = { module = "org.springframework.boot:spring-boot-starter", version.ref = "jre8_springframework_boot" }
jre8_spring_boot_starter_web = { module = "org.springframework.boot:spring-boot-starter-web", version.ref = "jre8_springframework_boot" }
jre8_spring_boot_starter_test = { module = "org.springframework.boot:spring-boot-starter-test", version.ref = "jre8_springframework_boot" }
jre8_spring_boot_configuration_processor = { module = "org.springframework.boot:spring-boot-configuration-processor", version.ref = "jre8_springframework_boot" }
jre8_jackson_databind = { module = "com.fasterxml.jackson.core:jackson-databind", version.ref = "jre8_jackson_core" }
jre8_javax_servlet = { module = "javax.servlet:javax.servlet-api", version.ref = "jre8_javax_servlet" }
jre8_javax_servlet_jsp = { module = "javax.servlet.jsp:javax.servlet.jsp-api", version.ref = "jre8_javax_servlet_jsp" }

junit = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit" }
junit_bom = { module = "org.junit:junit-bom", version.ref = "junit" }
assertj = { module = "org.assertj:assertj-core", version.ref = "assertj" }
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
rootProject.name = "javite"

include("vite-spring-webmvc")
include("vite-spring-webmvc-jre8")
117 changes: 117 additions & 0 deletions vite-spring-webmvc-jre8/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import com.vanniktech.maven.publish.JavaLibrary
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.SonatypeHost

plugins {
`java-library`
alias(libs.plugins.publish.maven)
}

description = "Vite - Spring Web MVC for JRE 8"

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

tasks.withType<JavaCompile> {
options.release.set(8)
}

repositories {
mavenCentral()
}

dependencies {
implementation(libs.jre8.spring.core)
implementation(libs.jre8.spring.webmvc)
implementation(libs.jre8.spring.boot.starter)
implementation(libs.jre8.spring.boot.starter.web)
implementation(libs.jre8.jackson.databind)

compileOnly(libs.jre8.javax.servlet)
compileOnly(libs.jre8.javax.servlet.jsp)

annotationProcessor(libs.jre8.spring.boot.configuration.processor)
}

tasks.jar {
enabled = true
archiveClassifier.set("")
manifest {
attributes(
mapOf(
"Implementation-Title" to project.name,
"Implementation-Version" to project.version,
),
)
}
}

mavenPublishing {
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)

signAllPublications()
}

object Meta {
const val DESC = "Vite integration with Spring Web MVC for JRE8."
const val LICENSE = "MIT"
const val LICENSE_URL = "https://opensource.org/licenses/mit"
const val GITHUB_REPO = "benny123tw/javite"
const val DEVELOPER_ID = "benny123tw"
const val DEVELOPER_NAME = "Benny Yen"
const val DEVELOPER_ORGANIZATION = "io.github.benny123tw"
const val DEVELOPER_ORGANIZATION_URL = "https://www.github.com/benny123tw"
}

mavenPublishing {
println("Publish ${project.group}, ${project.name}, ${project.version}")
coordinates(project.group.toString(), project.name, project.version.toString())

// Correctly configure JavaLibrary with Javadoc and sources JARs
configure(
JavaLibrary(
javadocJar = JavadocJar.Javadoc(),
sourcesJar = true
)
)

pom {
name.set(project.name)
description.set(Meta.DESC)
inceptionYear.set("2024")
url.set(Meta.GITHUB_REPO)
licenses {
license {
name.set(Meta.LICENSE)
url.set(Meta.LICENSE_URL)
}
}
developers {
developer {
id.set(Meta.DEVELOPER_ID)
name.set(Meta.DEVELOPER_NAME)
organization.set(Meta.DEVELOPER_ORGANIZATION)
organizationUrl.set(Meta.DEVELOPER_ORGANIZATION_URL)
}
}
scm {
url.set("https://github.com/${Meta.GITHUB_REPO}.git")
connection.set("scm:git:git://github.com/${Meta.GITHUB_REPO}.git")
developerConnection.set("scm:git:git://github.com/${Meta.GITHUB_REPO}.git")
}
issueManagement {
url.set("https://github.com/${Meta.GITHUB_REPO}/issues")
}
}
}

// gradle locking of dependency versions
// *required+used for trivy scan
dependencyLocking {
lockAllConfigurations()
}

// always run subproject task with parent
rootProject.tasks.dependencies { dependsOn(tasks.dependencies) }
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.github.benny123tw.servlet.annotation;

import io.github.benny123tw.servlet.config.ViteConfig;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import org.springframework.context.annotation.Import;

@Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Documented
@Import(ViteConfig.class)
public @interface EnableVite {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.github.benny123tw.servlet.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.beans.factory.annotation.Value;

/**
* Provides an out-of-the-box configuration for Vite.
*/
@Configuration
@ComponentScan(basePackages = "io.github.benny123tw.servlet.config")
public class ViteConfig {

@Value("${vite.debug:true}")
private boolean debug;

@Value("${vite.manifestPath:/WEB-INF/dist/.vite/manifest.json}")
private String manifestPath;

@Value("${vite.localServerUrl:http://localhost:5173}")
private String localServerUrl;

@Value("${vite.resourcePath:/resources}")
private String resourcePath;

@Bean
public ViteProperties viteProperties() {
ViteProperties viteProperties = new ViteProperties();
viteProperties.setDebug(debug);
viteProperties.setManifestPath(manifestPath);
viteProperties.setLocalServerUrl(localServerUrl);
viteProperties.setResourcePath(resourcePath);
return viteProperties;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package io.github.benny123tw.servlet.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties(prefix = "vite")
public class ViteProperties {

/**
* Whether to enable debug mode in Vite.
*/
private boolean debug = true;

/**
* The path of the manifest file generated by Vite.
*/
private String manifestPath = "/WEB-INF/dist/.vite/manifest.json";

/**
* The local server URL for Vite development.
*/
private String localServerUrl = "http://localhost:5173";

/**
* The path to the resources.
*/
private String resourcePath = "/resources";

public boolean isDebug() {
return debug;
}

public void setDebug(boolean debug) {
this.debug = debug;
}

public String getManifestPath() {
return manifestPath;
}

public void setManifestPath(String manifestPath) {
this.manifestPath = manifestPath;
}

public String getLocalServerUrl() {
return localServerUrl;
}

public void setLocalServerUrl(String localServerUrl) {
this.localServerUrl = localServerUrl;
}

public String getResourcePath() {
return resourcePath;
}

public void setResourcePath(String resourcePath) {
this.resourcePath = resourcePath;
}

}
Loading

0 comments on commit 8167835

Please sign in to comment.