|
| 1 | +import com.diffplug.spotless.LineEnding |
| 2 | + |
| 3 | +plugins { |
| 4 | + id("java-library") |
| 5 | + id("maven-publish") |
| 6 | + id("signing") |
| 7 | + id("com.diffplug.spotless").version("7.2.1") |
| 8 | + id("com.gradleup.nmcp.aggregation").version("1.1.0") |
| 9 | +} |
| 10 | + |
| 11 | +group = "io.github.malczuuu.problem4j" |
| 12 | + |
| 13 | +/** |
| 14 | + * In order to avoid hardcoding snapshot versions, we derive the version from the current Git commit hash. For CI/CD add |
| 15 | + * -Pversion={releaseVersion} parameter to match Git tag. |
| 16 | + */ |
| 17 | +version = |
| 18 | + if (version == "unspecified") |
| 19 | + getSnapshotVersion(rootProject.rootDir) |
| 20 | + else |
| 21 | + version |
| 22 | + |
| 23 | +java { |
| 24 | + toolchain.languageVersion = JavaLanguageVersion.of(8) |
| 25 | + withSourcesJar() |
| 26 | + withJavadocJar() |
| 27 | +} |
| 28 | + |
| 29 | +repositories { |
| 30 | + mavenCentral() |
| 31 | +} |
| 32 | + |
| 33 | +dependencies { |
| 34 | + testImplementation(platform("org.junit:junit-bom:5.13.4")) |
| 35 | + |
| 36 | + testImplementation("org.junit.jupiter:junit-jupiter") |
| 37 | + testRuntimeOnly("org.junit.platform:junit-platform-launcher") |
| 38 | +} |
| 39 | + |
| 40 | +publishing { |
| 41 | + publications { |
| 42 | + create<MavenPublication>("maven") { |
| 43 | + groupId = project.group.toString() |
| 44 | + artifactId = project.name |
| 45 | + version = project.version.toString() |
| 46 | + from(components["java"]) |
| 47 | + |
| 48 | + pom { |
| 49 | + name = project.name |
| 50 | + description = "Core library implementing Problem model according to RFC7807" |
| 51 | + url = "https://github.com/malczuuu/${project.name}" |
| 52 | + inceptionYear = "2025" |
| 53 | + licenses { |
| 54 | + license { |
| 55 | + name = "MIT License" |
| 56 | + url = "https://opensource.org/licenses/MIT" |
| 57 | + } |
| 58 | + } |
| 59 | + developers { |
| 60 | + developer { |
| 61 | + id = "malczuuu" |
| 62 | + name = "Damian Malczewski" |
| 63 | + url = "https://github.com/malczuuu" |
| 64 | + } |
| 65 | + } |
| 66 | + issueManagement { |
| 67 | + system = "GitHub Issues" |
| 68 | + url = "https://github.com/malczuuu/${project.name}/issues" |
| 69 | + } |
| 70 | + scm { |
| 71 | + connection = "scm:git:git://github.com/malczuuu/${project.name}.git" |
| 72 | + developerConnection = "scm:git:[email protected]:malczuuu/${project.name}.git" |
| 73 | + url = "https://github.com/malczuuu/${project.name}" |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +nmcpAggregation { |
| 81 | + centralPortal { |
| 82 | + username = System.getenv("PUBLISHING_USERNAME") |
| 83 | + password = System.getenv("PUBLISHING_PASSWORD") |
| 84 | + |
| 85 | + publishingType = "USER_MANAGED" |
| 86 | + } |
| 87 | + publishAllProjectsProbablyBreakingProjectIsolation() |
| 88 | +} |
| 89 | + |
| 90 | +signing { |
| 91 | + if (project.hasProperty("sign")) { |
| 92 | + useInMemoryPgpKeys( |
| 93 | + System.getenv("SIGNING_KEY"), |
| 94 | + System.getenv("SIGNING_PASSWORD") |
| 95 | + ) |
| 96 | + sign(publishing.publications["maven"]) |
| 97 | + } |
| 98 | +} |
| 99 | + |
| 100 | +spotless { |
| 101 | + format("misc") { |
| 102 | + target("**/*.gradle.kts", "**/.gitattributes", "**/.gitignore") |
| 103 | + |
| 104 | + trimTrailingWhitespace() |
| 105 | + leadingTabsToSpaces(4) |
| 106 | + endWithNewline() |
| 107 | + lineEndings = LineEnding.UNIX |
| 108 | + } |
| 109 | + |
| 110 | + java { |
| 111 | + target("src/**/*.java") |
| 112 | + |
| 113 | + googleJavaFormat("1.28.0") |
| 114 | + lineEndings = LineEnding.UNIX |
| 115 | + } |
| 116 | +} |
| 117 | + |
| 118 | +tasks.register("printVersion") { |
| 119 | + doLast { |
| 120 | + println("Project version: $version") |
| 121 | + } |
| 122 | +} |
| 123 | + |
| 124 | +tasks.withType<JavaCompile>().configureEach { |
| 125 | + options.compilerArgs.add("-parameters") |
| 126 | +} |
| 127 | + |
| 128 | +/** |
| 129 | + * Disable doclint to avoid errors and warnings on missing JavaDoc comments. |
| 130 | + */ |
| 131 | +tasks.withType<Javadoc>().configureEach { |
| 132 | + (options as StandardJavadocDocletOptions).apply { |
| 133 | + addStringOption("Xdoclint:none", "-quiet") |
| 134 | + } |
| 135 | +} |
| 136 | + |
| 137 | +tasks.withType<Test>().configureEach { |
| 138 | + useJUnitPlatform() |
| 139 | +} |
0 commit comments