From 2c0c6c22f4103bcc0792dbbb1365130590a5714d Mon Sep 17 00:00:00 2001 From: dingzhaojun Date: Thu, 17 Oct 2024 06:30:58 +0800 Subject: [PATCH] small update --- y9plugins/build.gradle | 55 +++-------- .../Y9BuildLogicPluginFunctionalTest.java | 56 ----------- .../groovy/net.risesoft.y9.aspectj.gradle | 36 +++++++ .../main/groovy/net.risesoft.y9.docker.gradle | 32 +++++++ .../net.risesoft.y9.java-conventions.gradle | 94 +++++++++++++++++++ .../groovy/net.risesoft.y9.smart-doc.gradle | 10 ++ .../java/org/example/Y9BuildLogicPlugin.java | 19 ---- .../org/example/Y9BuildLogicPluginTest.java | 23 ----- 8 files changed, 183 insertions(+), 142 deletions(-) delete mode 100644 y9plugins/src/functionalTest/java/org/example/Y9BuildLogicPluginFunctionalTest.java create mode 100644 y9plugins/src/main/groovy/net.risesoft.y9.aspectj.gradle create mode 100644 y9plugins/src/main/groovy/net.risesoft.y9.docker.gradle create mode 100644 y9plugins/src/main/groovy/net.risesoft.y9.java-conventions.gradle create mode 100644 y9plugins/src/main/groovy/net.risesoft.y9.smart-doc.gradle delete mode 100644 y9plugins/src/main/java/org/example/Y9BuildLogicPlugin.java delete mode 100644 y9plugins/src/test/java/org/example/Y9BuildLogicPluginTest.java diff --git a/y9plugins/build.gradle b/y9plugins/build.gradle index 605e269..22f828f 100644 --- a/y9plugins/build.gradle +++ b/y9plugins/build.gradle @@ -1,51 +1,18 @@ plugins { - id 'groovy-gradle-plugin' - id 'com.gradle.plugin-publish' version '1.3.0' + id 'groovy-gradle-plugin' //groovy DSL + id 'com.gradle.plugin-publish' version '1.3.0' //这个plugin本身已经包含了Java-gradle-plugin和maven-publish } -repositories { - // Use Maven Central for resolving dependencies. - mavenCentral() -} - -testing { - suites { - // Configure the built-in test suite - test { - // Use JUnit Jupiter test framework - useJUnitJupiter('5.10.3') - } - - // Create a new test suite - functionalTest(JvmTestSuite) { - dependencies { - // functionalTest test suite depends on the production code in tests - implementation project() - } - - targets { - all { - // This test suite should run after the built-in test suite has run its tests - testTask.configure { shouldRunAfter(test) } - } - } - } - } -} +group = 'net.risesoft.y9' +version = '1.0' gradlePlugin { - // Define the plugin - plugins { - greeting { - id = 'org.example.greeting' - implementationClass = 'org.example.Y9BuildLogicPlugin' - } - } + website = 'https://svn.youshengyun.com:3000/risesoft/y9-build-logic' + vcsUrl = 'https://svn.youshengyun.com:3000/risesoft/y9-build-logic' + } -gradlePlugin.testSourceSets.add(sourceSets.functionalTest) - -tasks.named('check') { - // Include functionalTest as part of the check lifecycle - dependsOn(testing.suites.functionalTest) -} +// https://docs.gradle.org/current/userguide/publishing_gradle_module_metadata.html#sub:disabling-gmm-publication +tasks.withType(GenerateModuleMetadata) { + enabled = false +} \ No newline at end of file diff --git a/y9plugins/src/functionalTest/java/org/example/Y9BuildLogicPluginFunctionalTest.java b/y9plugins/src/functionalTest/java/org/example/Y9BuildLogicPluginFunctionalTest.java deleted file mode 100644 index 430df5f..0000000 --- a/y9plugins/src/functionalTest/java/org/example/Y9BuildLogicPluginFunctionalTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This source file was generated by the Gradle 'init' task - */ -package org.example; - -import java.io.File; -import java.io.IOException; -import java.io.Writer; -import java.io.FileWriter; -import java.nio.file.Files; -import org.gradle.testkit.runner.GradleRunner; -import org.gradle.testkit.runner.BuildResult; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.io.TempDir; -import static org.junit.jupiter.api.Assertions.*; - -/** - * A simple functional test for the 'org.example.greeting' plugin. - */ -class Y9BuildLogicPluginFunctionalTest { - @TempDir - File projectDir; - - private File getBuildFile() { - return new File(projectDir, "build.gradle"); - } - - private File getSettingsFile() { - return new File(projectDir, "settings.gradle"); - } - - @Test void canRunTask() throws IOException { - writeString(getSettingsFile(), ""); - writeString(getBuildFile(), - "plugins {" + - " id('org.example.greeting')" + - "}"); - - // Run the build - GradleRunner runner = GradleRunner.create(); - runner.forwardOutput(); - runner.withPluginClasspath(); - runner.withArguments("greeting"); - runner.withProjectDir(projectDir); - BuildResult result = runner.build(); - - // Verify the result - assertTrue(result.getOutput().contains("Hello from plugin 'org.example.greeting'")); - } - - private void writeString(File file, String string) throws IOException { - try (Writer writer = new FileWriter(file)) { - writer.write(string); - } - } -} diff --git a/y9plugins/src/main/groovy/net.risesoft.y9.aspectj.gradle b/y9plugins/src/main/groovy/net.risesoft.y9.aspectj.gradle new file mode 100644 index 0000000..82cb62a --- /dev/null +++ b/y9plugins/src/main/groovy/net.risesoft.y9.aspectj.gradle @@ -0,0 +1,36 @@ +plugins { + id "io.freefair.aspectj.post-compile-weaving" +} + +println "apply plugin 'io.freefair.aspectj.post-compile-weaving' for ${project.name}" + +dependencies { + api libs.org.aspectj.aspectjrt + api libs.org.aspectj.aspectjtools + + aspect libs.org.springframework.spring.aspects + testAspect libs.org.springframework.spring.aspects +} + +compileJava { + ajc { + enabled = true + classpath + options { + aspectpath.setFrom configurations.aspect + compilerArgs = [] + compilerArgs += "-showWeaveInfo -verbose" + } + } +} + +compileTestJava { + ajc { + enabled = true + classpath + options { + aspectpath.setFrom configurations.testAspect + compilerArgs = [] + } + } +} diff --git a/y9plugins/src/main/groovy/net.risesoft.y9.docker.gradle b/y9plugins/src/main/groovy/net.risesoft.y9.docker.gradle new file mode 100644 index 0000000..70b7e8f --- /dev/null +++ b/y9plugins/src/main/groovy/net.risesoft.y9.docker.gradle @@ -0,0 +1,32 @@ +plugins { + id 'com.google.cloud.tools.jib' +} + +println "apply plugin 'com.google.cloud.tools.jib' for ${project.name}" + +def dateTimeStr = new Date().format("yyyyMMddHHmm") + +jib { + from { + image = 'docker-internal.youshengyun.com/tomcat:10.1-jre21-temurin' + platforms { + platform { + architecture = 'amd64' + os = 'linux' + } + platform { + architecture = 'arm64' + os = 'linux' + } + } + } +// container.appRoot = "/usr/local/tomcat/webapps/app" + to { + image "docker-registry-internal.youshengyun.com/${project.name}" + auth { + username = findProperty("dockerUsername") ?: "" + password = findProperty("dockerPassword") ?: "" + } + tags = ['v9.7.0-SNAPSHOT', 'v9.7.x', "v9.7.0-SNAPSHOT-${dateTimeStr}"] + } +} \ No newline at end of file diff --git a/y9plugins/src/main/groovy/net.risesoft.y9.java-conventions.gradle b/y9plugins/src/main/groovy/net.risesoft.y9.java-conventions.gradle new file mode 100644 index 0000000..d4d6be3 --- /dev/null +++ b/y9plugins/src/main/groovy/net.risesoft.y9.java-conventions.gradle @@ -0,0 +1,94 @@ +/* + * This file was generated by the Gradle 'init' task. + * + * This project uses @Incubating APIs which are subject to change. + */ + +plugins { + id 'java-library' + id 'maven-publish' + id 'signing' +} + +repositories { + mavenLocal() + maven { + url = uri('https://repo.spring.io/snapshot') + } + + maven { + url = uri('https://repo.spring.io/milestone') + } + + maven { + url = uri('https://maven.aliyun.com/repository/public') + } + + maven { + url = uri('https://svn.youshengyun.com:9900/nexus/repository/maven-public/') + } + + maven { + url = uri('https://repo.maven.apache.org/maven2/') + } + + maven { + url = uri('https://build.shibboleth.net/maven/releases/') + } + + maven { + url = uri('https://build.shibboleth.net/maven/snapshots/') + } +} + +group = 'net.risesoft' +version = 'v9.7.0-SNAPSHOT' +java.sourceCompatibility = JavaVersion.VERSION_21 + +java { + withJavadocJar() + withSourcesJar() +} + +compileJava { + options.compilerArgs << '-parameters' +} + +publishing { + publications { + maven(MavenPublication) { + from(components.java) + } + } + repositories { + maven { + name = 'y9-internet-repo' + url = 'https://svn.youshengyun.com:9900/nexus/repository/maven-snapshots/' + credentials { + username = findProperty("mavenUsername") ?: "" + password = findProject("mavenPassword") ?: "" + } +// name = 'myRepo' +// url = layout.buildDirectory.dir("repo") + } + } +} + +signing { + useGpgCmd() + sign publishing.publications.maven +} + +tasks.withType(JavaCompile) { + options.encoding = 'UTF-8' +} + +tasks.withType(Javadoc) { + options.encoding = 'UTF-8' + failOnError = false + options.addStringOption('Xdoclint:none', '-quiet') // 禁用所有文档检查 +} + +tasks.withType(GenerateModuleMetadata) { + enabled = false +} diff --git a/y9plugins/src/main/groovy/net.risesoft.y9.smart-doc.gradle b/y9plugins/src/main/groovy/net.risesoft.y9.smart-doc.gradle new file mode 100644 index 0000000..d247f51 --- /dev/null +++ b/y9plugins/src/main/groovy/net.risesoft.y9.smart-doc.gradle @@ -0,0 +1,10 @@ +plugins { + id 'com.ly.smart-doc' +} + +println "apply plugin 'com.ly.smart-doc' for ${project.name}" + +smartdoc { + configFile = file("src/main/resources/smart-doc.json") + include 'net.risesoft*' +} \ No newline at end of file diff --git a/y9plugins/src/main/java/org/example/Y9BuildLogicPlugin.java b/y9plugins/src/main/java/org/example/Y9BuildLogicPlugin.java deleted file mode 100644 index 70253f0..0000000 --- a/y9plugins/src/main/java/org/example/Y9BuildLogicPlugin.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * This source file was generated by the Gradle 'init' task - */ -package org.example; - -import org.gradle.api.Project; -import org.gradle.api.Plugin; - -/** - * A simple 'hello world' plugin. - */ -public class Y9BuildLogicPlugin implements Plugin { - public void apply(Project project) { - // Register a task - project.getTasks().register("greeting", task -> { - task.doLast(s -> System.out.println("Hello from plugin 'org.example.greeting'")); - }); - } -} diff --git a/y9plugins/src/test/java/org/example/Y9BuildLogicPluginTest.java b/y9plugins/src/test/java/org/example/Y9BuildLogicPluginTest.java deleted file mode 100644 index 0dbab15..0000000 --- a/y9plugins/src/test/java/org/example/Y9BuildLogicPluginTest.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * This source file was generated by the Gradle 'init' task - */ -package org.example; - -import org.gradle.testfixtures.ProjectBuilder; -import org.gradle.api.Project; -import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; - -/** - * A simple unit test for the 'org.example.greeting' plugin. - */ -class Y9BuildLogicPluginTest { - @Test void pluginRegistersATask() { - // Create a test project and apply the plugin - Project project = ProjectBuilder.builder().build(); - project.getPlugins().apply("org.example.greeting"); - - // Verify the result - assertNotNull(project.getTasks().findByName("greeting")); - } -}