Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring new project #45

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
102 changes: 102 additions & 0 deletions generate-project.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@

def javaVersion = project.hasProperty('javaVersion') ? project.getProperty('javaVersion') : '17'
def gradleVersion = project.hasProperty('gradleVersion') ? project.getProperty('gradleVersion') : '8.5'
def springBootVersion = project.hasProperty('springBootVersion') ? project.getProperty('springBootVersion') : '3.1.0'
def openApiSpecDir = project.hasProperty('openApiSpecDir') ? project.getProperty('openApiSpecDir') : 'spec/spi'
def openApiGeneratorVersion = project.hasProperty('openApiGeneratorVersion') ? project.getProperty('openApiGeneratorVersion') : '6.6.0'

task generateSpringBootProject {
doLast {
def projectDir = file("generated-spring-boot-project")
projectDir.mkdirs()

def buildGradle = new File(projectDir, "build.gradle")
buildGradle.text = """
plugins {
id 'java'
id 'org.springframework.boot' version '${springBootVersion}'
id 'io.spring.dependency-management' version '1.1.0'
id 'org.openapi.generator' version '${openApiGeneratorVersion}'
}

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

java {
sourceCompatibility = JavaVersion.VERSION_${javaVersion}
}

repositories {
mavenCentral()
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'io.swagger.core.v3:swagger-annotations:2.2.8'
implementation 'org.openapitools:jackson-databind-nullable:0.2.6'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

def specDir = file("${openApiSpecDir}")
specDir.eachFile { file ->
if (file.name.endsWith('.yml') || file.name.endsWith('.yaml')) {
def taskName = "openApiGenerate_" + file.name.replaceAll("[^a-zA-Z0-9]", "_")
tasks.create(name: taskName, type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
generatorName = "spring"
inputSpec = file.absolutePath
outputDir = "$buildDir/generated-" + file.name
apiPackage = "com.example.api." + file.name.replaceAll("[^a-zA-Z0-9]", "").toLowerCase()
modelPackage = "com.example.model." + file.name.replaceAll("[^a-zA-Z0-9]", "").toLowerCase()
configOptions = [
dateLibrary: "java8",
interfaceOnly: "true",
skipDefaultInterface: "true"
]
}
compileJava.dependsOn tasks.named(taskName)
}
}

tasks.named('test') {
useJUnitPlatform()
}

sourceSets {
main {
java {
srcDirs = ["$buildDir/generated-*/src/main/java", 'src/main/java']
}
}
}
"""

def settingsGradle = new File(projectDir, "settings.gradle")
settingsGradle.text = "rootProject.name = 'spring-boot-openapi-project'"

def srcDir = new File(projectDir, "src/main/java/com/example")
srcDir.mkdirs()
def applicationJava = new File(srcDir, "Application.java")
applicationJava.text = """
package com.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
"""

exec {
workingDir projectDir
commandLine 'gradle', 'wrapper', '--gradle-version', gradleVersion
}

println "Spring Boot project generated successfully in 'generated-spring-boot-project' directory."
println "To build the project, navigate to the directory and run: ./gradlew build"
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#Thu Oct 03 14:05:38 IST 2024
gradle.version=8.10.2
Binary file not shown.
Empty file.
58 changes: 58 additions & 0 deletions generated-spring-boot-project/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

plugins {
id 'java'
id 'org.springframework.boot' version '3.1.0'
id 'io.spring.dependency-management' version '1.1.0'
id 'org.openapi.generator' version '6.6.0'
}

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

java {
sourceCompatibility = JavaVersion.VERSION_17
}

repositories {
mavenCentral()
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'io.swagger.core.v3:swagger-annotations:2.2.8'
implementation 'org.openapitools:jackson-databind-nullable:0.2.6'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

def specDir = file("spec/spi")
specDir.eachFile { file ->
if (file.name.endsWith('.yml') || file.name.endsWith('.yaml')) {
def taskName = "openApiGenerate_" + file.name.replaceAll("[^a-zA-Z0-9]", "_")
tasks.create(name: taskName, type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
generatorName = "spring"
inputSpec = file.absolutePath
outputDir = "/Users/shishir/Documents/cb-provider-spi/build/generated-" + file.name
apiPackage = "com.example.api." + file.name.replaceAll("[^a-zA-Z0-9]", "").toLowerCase()
modelPackage = "com.example.model." + file.name.replaceAll("[^a-zA-Z0-9]", "").toLowerCase()
configOptions = [
dateLibrary: "java8",
interfaceOnly: "true",
skipDefaultInterface: "true"
]
}
compileJava.dependsOn tasks.named(taskName)
}
}

tasks.named('test') {
useJUnitPlatform()
}

sourceSets {
main {
java {
srcDirs = ["/Users/shishir/Documents/cb-provider-spi/build/generated-*/src/main/java", 'src/main/java']
}
}
}
1 change: 1 addition & 0 deletions generated-spring-boot-project/build/bootJarMainClassName
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.example.Application
1 change: 1 addition & 0 deletions generated-spring-boot-project/build/bootRunMainClassName
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.example.Application
9 changes: 9 additions & 0 deletions generated-spring-boot-project/build/tmp/bootJar/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Manifest-Version: 1.0
Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: com.example.Application
Spring-Boot-Version: 2.7.0
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/
Spring-Boot-Classpath-Index: BOOT-INF/classpath.idx
Spring-Boot-Layers-Index: BOOT-INF/layers.idx

Binary file not shown.
2 changes: 2 additions & 0 deletions generated-spring-boot-project/build/tmp/jar/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Manifest-Version: 1.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading
Loading