diff --git a/CHANGELOG.md b/CHANGELOG.md index 287520857..cfb73102f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Use Java 17 (LTS) in maven jenkins-agent and spring boot qs ([#651](https://github.com/opendevstack/ods-quickstarters/pull/651)) - ODS AMI build fails due to failing jacoco report generation in springboot quickstarter ([#700](https://github.com/opendevstack/ods-quickstarters/pull/700)) - terraform agent sops/age added ([#730](https://github.com/opendevstack/ods-quickstarters/issues/730)) +- Allow local project creation of quickstarter be-java-springboot ([#761](https://github.com/opendevstack/ods-quickstarters/pull/761)) ### Fixed diff --git a/be-java-springboot/Jenkinsfile b/be-java-springboot/Jenkinsfile index e65a3c1cf..c40b6a25a 100644 --- a/be-java-springboot/Jenkinsfile +++ b/be-java-springboot/Jenkinsfile @@ -22,52 +22,19 @@ odsQuickstarterPipeline( dir(context.targetDir) { def springBootVersion = '2.6.1.RELEASE' echo "--- create spring boot (v${springBootVersion}) project via spring initializr ---" - - sh "curl https://start.spring.io/starter.tgz \ - -d type=gradle-project \ - -d language=java \ - -d dependencies='web,data-rest,restdocs,data-jpa,h2,security,devtools' \ - -d bootVersion=${springBootVersion} \ - -d packaging=jar \ - -d javaVersion=17 \ - -d groupId=${context.projectId} \ - -d artifactId=${context.componentId} \ - -d name=${context.componentId} \ - -d description='OpenDevStack%20Demo%20Project%20for%20Spring%20Boot' \ - -d packageName='${context.packageName}' \ - | tar -zxvf - " + sh "make create-project TARGET_DIR=. SPRING_BOOT_CLI_VERSION=${springBootVersion} PROJECT_ID=${context.projectId} COMPONENT_ID=${context.componentId} PACKAGE_NAME=${context.packageName}" echo "--- configure application.properties ---" + sh "make add-sb-app-properties TARGET_DIR=." - sh "echo 'spring.profiles.active: dev' > src/main/resources/application.properties" - sh "echo 'spring.jpa.database: HSQL' > src/main/resources/application-dev.properties" - } - - echo "--- customise build.gradle ---" - - // enforce minimal log4j2 version to avoid (CVE-2021-44228) - sh "sed -i -e '/ext {/{r ${context.sourceDir}/templates/gradle-minimal-log4j2-version.template' -e 'd' -e '}' ${context.targetDir}/build.gradle" - - // add nexus credential settings - sh "cat ${context.sourceDir}/templates/gradle-buildscript.template ${context.targetDir}/build.gradle >out && mv out ${context.targetDir}/build.gradle" + echo "--- customise build.gradle ---" + sh "pwd && ls -lart" + sh "make customise-build-gradle SOURCE_DIR=../${context.sourceDir} TARGET_DIR=." + sh "rm Makefile" - // insert required plugins - sh "sed -i -e '/plugins {/{r ${context.sourceDir}/templates/gradle-plugins.template' -e 'd' -e '}' ${context.targetDir}/build.gradle" - - // insert nexus repos - sh "sed -i -e '/mavenCentral()/{r ${context.sourceDir}/templates/gradle-repositories.template' -e 'd' -e '}' ${context.targetDir}/build.gradle" - - // insert test settings - sh "sed -i -e '/test {/{r ${context.sourceDir}/templates/gradle-plugin-test.template' -e 'd' -e '}' ${context.targetDir}/build.gradle" - - // append bootJar settings - sh "cat ${context.sourceDir}/templates/gradle-plugin-bootjar.template >> ${context.targetDir}/build.gradle" - - // append jacoco settings - sh "cat ${context.sourceDir}/templates/gradle-plugin-jacoco.template >> ${context.targetDir}/build.gradle" + echo "--- end stage Build spring project ---" + } - // append maven-publish settings - sh "cat ${context.sourceDir}/templates/gradle-maven-publish.template >> ${context.targetDir}/build.gradle" } odsQuickstarterStageCopyFiles(context) diff --git a/be-java-springboot/Makefile b/be-java-springboot/Makefile new file mode 100644 index 000000000..aab144f42 --- /dev/null +++ b/be-java-springboot/Makefile @@ -0,0 +1,66 @@ +SHELL = /bin/bash +.SHELLFLAGS := -eu -o pipefail -c +.DELETE_ON_ERROR: +MAKEFLAGS += --warn-undefined-variables +MAKEFLAGS += --no-builtin-rules + +SOURCE_DIR=${sourceDir} +TARGET_DIR=${targetDir} +SPRING_BOOT_CLI_VERSION=${springBootVersion} +PROJECT_ID=${projectId} +COMPONENT_ID=${componentId} +PACKAGE_NAME=${packageName} + +# create-project +create-project: + mkdir -p ${TARGET_DIR} + cd ${TARGET_DIR} && curl https://start.spring.io/starter.tgz \ + -d type=gradle-project \ + -d language=java \ + -d dependencies='web,jersey,data-jpa,h2,data-rest,restdocs,security' \ + -d bootVersion=${SPRING_BOOT_CLI_VERSION} \ + -d packaging=jar \ + -d javaVersion=17 \ + -d groupId=${PROJECT_ID} \ + -d artifactId=${COMPONENT_ID} \ + -d name=${COMPONENT_ID} \ + -d description='OpenDevStack%20Demo%20Project%20for%20Spring%20Boot' \ + -d packageName='${PACKAGE_NAME}' \ + | tar -zxvf - + +.PHONY: create-project +# add-sb-app-properties +add-sb-app-properties: + echo 'spring.profiles.active: dev' > ${TARGET_DIR}/src/main/resources/application.properties + echo 'spring.jpa.database: HSQL' > ${TARGET_DIR}/src/main/resources/application-dev.properties +.PHONY: add-sb-app-properties +# customise-build-gradle +customise-build-gradle: + echo "called customise-build-gradle..." + + echo "...enforce minimal log4j2 version to avoid (CVE-2021-44228)" + sed -i -e '/ext {/{r ${SOURCE_DIR}/templates/gradle-minimal-log4j2-version.template' -e 'd' -e '}' ${TARGET_DIR}/build.gradle + + echo "...add nexus credential settings" + cat ${SOURCE_DIR}/templates/gradle-buildscript.template ${TARGET_DIR}/build.gradle >out && mv out ${TARGET_DIR}/build.gradle + + echo "...insert required plugins" + sed -i -e '/plugins {/{r ${SOURCE_DIR}/templates/gradle-plugins.template' -e 'd' -e '}' ${TARGET_DIR}/build.gradle + + echo "...insert nexus repos" + sed -i -e '/mavenCentral()/{r ${SOURCE_DIR}/templates/gradle-repositories.template' -e 'd' -e '}' ${TARGET_DIR}/build.gradle + + echo "...insert test settings" + sed -i -e '/test {/{r ${SOURCE_DIR}/templates/gradle-plugin-test.template' -e 'd' -e '}' ${TARGET_DIR}/build.gradle + + echo "...append bootJar settings" + cat ${SOURCE_DIR}/templates/gradle-plugin-bootjar.template >> ${TARGET_DIR}/build.gradle + + echo "...append jacoco settings" + cat ${SOURCE_DIR}/templates/gradle-plugin-jacoco.template >> ${TARGET_DIR}/build.gradle + + echo "...append maven-publish settings" + cat ${SOURCE_DIR}/templates/gradle-maven-publish.template >> ${TARGET_DIR}/build.gradle + +.PHONY: customise-build-gradle +