Skip to content

Commit

Permalink
TS-41699 Migrate maven plugin build to Gradle
Browse files Browse the repository at this point in the history
  • Loading branch information
DreierF committed Feb 2, 2025
1 parent 45d47e3 commit 8497ec8
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 903 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ plugins {

group = "com.teamscale"

repositories {
mavenCentral()
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
Expand Down
3 changes: 3 additions & 0 deletions buildSrc/src/main/kotlin/com.teamscale.publish.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ fun PublicationContainer.configureMavenPublication() {
pluginManager.withPlugin("java-library") {
from(components["java"])
}
pluginManager.withPlugin("org.gradlex.maven-plugin-development") {
from(components["java"])
}
}
}
}
6 changes: 6 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ okhttp = "4.12.0"
mockito = "5.15.2"
mockitoKotlin = "5.4.0"
picocli = "4.7.6"
maven = "3.9.9"

[libraries]
jetty-server = { module = "org.eclipse.jetty:jetty-server", version.ref = "jetty" }
Expand Down Expand Up @@ -80,9 +81,14 @@ mockito-kotlin = { module = "org.mockito.kotlin:mockito-kotlin", version.ref = "

springboot-loader = { module = "org.springframework.boot:spring-boot-loader", version = "3.4.2" }

maven-core = { module = "org.apache.maven:maven-core", version.ref = "maven" }
maven-pluginApi = { module = "org.apache.maven:maven-plugin-api", version.ref = "maven" }
maven-pluginAnnotations = { module = "org.apache.maven.plugin-tools:maven-plugin-annotations", version = "3.15.1" }

[plugins]
versions = { id = "com.github.ben-manes.versions", version = "0.52.0" }
markdownToPdf = { id = "de.fntsoftware.gradle.markdown-to-pdf", version = "1.1.0" }
nexusPublish = { id = "io.github.gradle-nexus.publish-plugin", version = "2.0.0" }
pluginPublish = { id = "com.gradle.plugin-publish", version = "1.3.1" }
gitProperties = { id = "com.gorylenko.gradle-git-properties", version = "2.4.2" }
mavenPluginDevelopment = { id = "org.gradlex.maven-plugin-development", version = "1.0.2" }
6 changes: 6 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
dependencyResolutionManagement {
repositories {
mavenCentral()
}
}

pluginManagement {
plugins {
kotlin("jvm") version "2.1.10"
Expand Down
3 changes: 0 additions & 3 deletions teamscale-maven-plugin/.gitignore

This file was deleted.

20 changes: 0 additions & 20 deletions teamscale-maven-plugin/.mvn/wrapper/maven-wrapper.properties

This file was deleted.

7 changes: 1 addition & 6 deletions teamscale-maven-plugin/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# Teamscale Maven Plugin Dev Setup

## Import into IntelliJ
The JaCoCo agent repo uses gradle, but since we are developing a maven plugin, it also uses maven as nested build system.
To get code completion etc. in IntelliJ, open the maven tool window and click on sync (🔄) there.
This will un-sync the gradle projects but instead sync the `teamscale-maven-plugin` project

## Manual testing
When doing manual tests, you can attach the IntelliJ debugger to the JVM in which the tests are run.
Surefire (maven unit tests) creates its own JVM and you have to tell it to stop before the execution of the tests to attach a debugger.
Expand All @@ -15,4 +10,4 @@ So if you want to manually test the changes to the plugin you need to:
* Call `./gradlew publishToMavenLocal` to publish your plugin changes to your local maven cache
* Create a maven project with some tests and installed Teamscale plugin (see [Docs](https://docs.teamscale.com/howto/providing-testwise-coverage/#tia-with-maven-and-junit-5)). The version should be the one stated in the root level `build.gradle.kts` file with a `-SNAPSHOT` suffix, e.g. `33.2.0-SNAPSHOT`.
* In your maven project, call `mvn -Dmaven.surefire.debug verify`. The tests won't run until you do the next step.
* In IntelliJ, [create a Remote JVM debug run config](https://www.jetbrains.com/help/idea/attach-to-process.html#attach-to-remote) with default values. Set breakpoints in the code as needed and run the remote debug run config. The tests will resume now and your breakpoints in the plugin will be hit.
* In IntelliJ, [create a Remote JVM debug run config](https://www.jetbrains.com/help/idea/attach-to-process.html#attach-to-remote) with default values. Set breakpoints in the code as needed and run the remote debug run config. The tests will resume now and your breakpoints in the plugin will be hit.
2 changes: 0 additions & 2 deletions teamscale-maven-plugin/auto-format-pom.sh

This file was deleted.

111 changes: 21 additions & 90 deletions teamscale-maven-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,100 +1,31 @@
import org.apache.tools.ant.taskdefs.condition.Os

abstract class MavenExec : Exec() {
@TaskAction
override fun exec() {
executable = "./mvnw"
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
executable = "cmd"
args(listOf("/c", "mvnw.cmd") + (args ?: emptyList()))
}
workingDir(".")
project.file("pom.xml").writeText(
project.file("pom.xml").readText().replace(
Regex("<teamscale.agent.version>[^<]+</teamscale.agent.version>"),
"<teamscale.agent.version>${project.version}</teamscale.agent.version>"
).replace(
Regex("<revision>[^<]+</revision>"),
"<revision>${project.version}</revision>"
)
)
super.exec()
project.file("pom.xml").writeText(
project.file("pom.xml").readText().replace(
Regex("<teamscale.agent.version>[^<]+</teamscale.agent.version>"),
"<teamscale.agent.version>34.0.0</teamscale.agent.version>"
).replace(
Regex("<revision>[^<]+</revision>"),
"<revision>1.0.0-SNAPSHOT</revision>"
)
)
}
plugins {
alias(libs.plugins.mavenPluginDevelopment)
com.teamscale.`java-convention`
com.teamscale.coverage
com.teamscale.publish
}

tasks.register<MavenExec>("clean") {
group = "build"
description = "Cleans the build directory"
args("clean")
publishAs {
readableName.set("Teamscale Maven Plugin")
description.set("Maven Plugin for Teamscale")
}

tasks.register<MavenExec>("build") {
group = "build"
description = "Builds the project and runs tests"
args(
"verify",
"-Drevision=${project.version}",
"-Dteamscale.agent.version=${project.version}"
)
mavenPlugin {
helpMojoPackage.set("com.teamscale.maven.help")
}

tasks.register<MavenExec>("publishToMavenLocal") {
group = "publishing"
description = "Publishes the project to the local Maven repository"
args(
"install",
"-Drevision=${project.version}",
"-Dteamscale.agent.version=${project.version}"
)
}
dependencies {
implementation(project(":agent"))
implementation(project(":report-generator"))
implementation(project(":teamscale-client"))

tasks.withType<MavenExec> {
if (name != "clean") {
dependsOn(":agent:publishToMavenLocal")
dependsOn(":teamscale-client:publishToMavenLocal")
dependsOn(":impacted-test-engine:publishToMavenLocal")
}
}
compileOnly(libs.maven.core)
implementation(libs.maven.pluginApi)
compileOnly(libs.maven.pluginAnnotations)

if (project.hasProperty("sonatypeUsername") &&
project.hasProperty("sonatypePassword") &&
project.hasProperty("signing.keyId") &&
project.hasProperty("gpgDirectory")
) {
implementation(libs.jgit)
implementation(libs.teamscaleLibCommons)

tasks.register<MavenExec>("publishMavenPublicationToSonatypeRepository") {
group = "publishing"
description = "Publishes the Maven publication to the Sonatype repository"
doFirst {
file("/tmp/maven-settings.xml").writeText(
"""
<settings>
<servers>
<server>
<id>ossrh</id>
<username>${project.property("sonatypeUsername")}</username>
<password>${project.property("sonatypePassword")}</password>
</server>
</servers>
</settings>
"""
)
}
args(
"deploy", "-s", "/tmp/maven-settings.xml",
"-Dgpg.passphrase=${project.property("signing.password")}",
"-Dgpg.homedir=${project.property("gpgDirectory")}",
"-Dgpg.keyname=${project.property("signing.keyId")}",
"-DsecretKeyRingFile=${project.property("signing.secretKeyRingFile")}"
)
}
testImplementation(libs.junit.jupiter.api)
testImplementation(libs.assertj)
}
Loading

0 comments on commit 8497ec8

Please sign in to comment.