MapWithAI/build.gradle

294 wiersze
8.5 KiB
Groovy
Czysty Zwykły widok Historia

import net.ltgt.gradle.errorprone.CheckSeverity
import org.openstreetmap.josm.gradle.plugin.task.GeneratePluginList
import java.nio.file.Files
import java.nio.file.Paths
plugins {
id "java"
id "eclipse"
id "jacoco"
id "maven-publish"
id "pmd"
id "com.github.ben-manes.versions" version "0.38.0"
id "com.github.spotbugs" version "4.7.0"
id "org.openstreetmap.josm" version "0.7.1"
id "net.ltgt.errorprone" version "2.0.1"
id "com.diffplug.spotless" version "5.11.1"
id "org.sonarqube" version "3.1.1"
//id 'de.aaschmid.cpd' version '2.0'
}
java.sourceCompatibility = JavaVersion.VERSION_1_8
java.targetCompatibility = JavaVersion.VERSION_1_8
// Set up Errorprone
tasks.withType(JavaCompile).configureEach {
options.errorprone {
check("DefaultCharset", CheckSeverity.ERROR)
check("StringEquality", CheckSeverity.ERROR)
check("ConstantField", CheckSeverity.WARN)
check("FieldCanBeFinal", CheckSeverity.WARN)
check("LambdaFunctionalInterface", CheckSeverity.WARN)
check("MethodCanBeStatic", CheckSeverity.WARN)
check("MultiVariableDeclaration", CheckSeverity.WARN)
check("PrivateConstructorForUtilityClass", CheckSeverity.WARN)
check("UngroupedOverloads", CheckSeverity.WARN)
check("WildcardImport", CheckSeverity.WARN)
}
}
archivesBaseName = "mapwithai"
def gitlabGroup = "gokaart"
def gitlabRepositoryName = "JOSM_MapWithAI"
repositories {
jcenter()
mavenCentral()
}
sourceSets {
test {
java {
srcDirs = ["test/unit"]
}
resources {
srcDirs = ["test/data"]
}
}
intTest {
compileClasspath += sourceSets.main.output
compileClasspath += sourceSets.test.output
runtimeClasspath += sourceSets.main.output
runtimeClasspath += sourceSets.test.output
java {
srcDirs = ["test/integration"]
}
resources {
srcDirs = ["test/data"]
}
}
}
def versions = [
awaitility: "4.0.3",
errorprone: "2.4.0",
jacoco: "0.8.5",
jmockit: "1.49",
junit: "5.7.1",
pmd: "6.20.0",
spotbugs: "4.2.2",
wiremock: "2.27.2",
findsecbugs: "1.11.0",
]
dependencies {
if (!JavaVersion.current().isJava9Compatible()) {
errorproneJavac("com.google.errorprone:javac:9+181-r4173-1")
}
spotbugsPlugins "com.h3xstream.findsecbugs:findsecbugs-plugin:${versions.findsecbugs}"
errorprone("com.google.errorprone:error_prone_core:${versions.errorprone}")
testImplementation("org.junit.jupiter:junit-jupiter-api:${versions.junit}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${versions.junit}")
testImplementation("org.junit.vintage:junit-vintage-engine:${versions.junit}")
testCompile("org.junit.jupiter:junit-jupiter-params:${versions.junit}")
testCompile("org.jmockit:jmockit:${versions.jmockit}")
testImplementation("com.github.spotbugs:spotbugs-annotations:${versions.spotbugs}")
testImplementation("org.openstreetmap.josm:josm-unittest:"){changing=true}
testImplementation("com.github.tomakehurst:wiremock:${versions.wiremock}")
testImplementation("org.awaitility:awaitility:${versions.awaitility}")
}
configurations {
intTestRuntimeOnly.extendsFrom testRuntimeOnly
intTestImplementation.extendsFrom testImplementation
}
// Add dependencies from ivy.xml
def ivyModule = new XmlParser().parse(new File("$projectDir/ivy.xml"))
logger.info("Dependencies from ivy.xml (added to configuration `packIntoJar`):")
ivyModule.dependencies.dependency.each {
logger.info(" * ${it.@org}:${it.@name}:${it.@rev}")
if (!"${it.@conf}".contains("test")) {
project.dependencies.packIntoJar("${it.@org}:${it.@name}:${it.@rev}")
}
}
test {
project.afterEvaluate {
jvmArgs("-javaagent:${classpath.find { it.name.contains("jmockit") }.absolutePath}")
jvmArgs("-Djunit.jupiter.extensions.autodetection.enabled=true")
jvmArgs("-Djava.awt.headless=true")
}
useJUnitPlatform()
ignoreFailures
testLogging {
exceptionFormat "full"
events "skipped", "failed"
info {
showStandardStreams true
}
}
}
task integrationTest(type: Test) {
description = "Run integration tests"
group = "verification"
testClassesDirs = sourceSets.intTest.output.classesDirs
classpath = sourceSets.intTest.runtimeClasspath
shouldRunAfter test
// Ignore failures -- servers may or may not be down
ignoreFailures = true
}
check.dependsOn integrationTest
tasks.processResources {
from("$projectDir/LICENSE")
from("$projectDir/README.md")
from("$projectDir/src/resources")
from("$projectDir/src/main/resources")
}
jacocoTestCoverageVerification {
violationRules {
rule {
limit {
minimum = 0.80
}
}
}
}
spotless {
java {
licenseHeader "// License: GPL. For details, see LICENSE file."
removeUnusedImports()
endWithNewline()
indentWithSpaces(4)
eclipse().configFile "config/josm_formatting.xml"
trimTrailingWhitespace()
}
}
josm {
debugPort = 7055
manifest {
oldVersionDownloadLink 16645, "v1.6.7", new URL("https://gokaart.gitlab.io/JOSM_MapWithAI/dist/v1.6.7/mapwithai.jar")
oldVersionDownloadLink 16284, "v1.5.9", new URL("https://gokaart.gitlab.io/JOSM_MapWithAI/dist/v1.5.9/mapwithai.jar")
oldVersionDownloadLink 16220, "v1.4.6", new URL("https://gokaart.gitlab.io/JOSM_MapWithAI/dist/v1.4.6/mapwithai.jar")
oldVersionDownloadLink 15820, "v1.3.10", new URL("https://gokaart.gitlab.io/JOSM_MapWithAI/dist/v1.3.10/mapwithai.jar")
oldVersionDownloadLink 15737, "v1.2.6", new URL("https://gokaart.gitlab.io/JOSM_MapWithAI/dist/v1.2.6/mapwithai.jar")
oldVersionDownloadLink 15609, "v1.1.11", new URL("https://gokaart.gitlab.io/JOSM_MapWithAI/dist/v1.1.11/mapwithai.jar")
oldVersionDownloadLink 15542, "v1.0.8", new URL("https://gokaart.gitlab.io/JOSM_MapWithAI/dist/v1.0.8/mapwithai.jar")
oldVersionDownloadLink 15233, "v0.2.13", new URL("https://gokaart.gitlab.io/JOSM_MapWithAI/dist/v0.2.13/mapwithai.jar")
}
i18n {
pathTransformer = getPathTransformer(project.projectDir, "gitlab.com/${gitlabGroup}/${gitlabRepositoryName}/blob")
}
}
tasks.withType(JavaCompile) {
options.compilerArgs += [
"-Xlint:all",
"-Xlint:-serial",
]
}
// Set up JaCoCo
jacoco {
toolVersion = "${versions.jacoco}"
}
jacocoTestReport {
dependsOn test
reports {
xml.enabled = true
html.enabled = true
}
}
check.dependsOn jacocoTestReport
// Set up PMD
pmd {
toolVersion = versions.pmd
ignoreFailures true
incrementalAnalysis = true
ruleSets = []
ruleSetConfig = resources.text.fromFile("$projectDir/config/pmd/ruleset.xml")
sourceSets = [sourceSets.main]
}
// Set up SpotBugs
spotbugs {
toolVersion = versions.spotbugs
ignoreFailures = true
}
spotbugsMain {
reports {
xml.enabled = false
html.enabled = true
}
}
task generateSnapshotUpdateSite(type: GeneratePluginList) {
dependsOn(tasks.processResources)
outputFile = new File(project.buildDir, "snapshot-update-site")
versionSuffix = {a -> ""}
doFirst {
def pluginDownloadUrl = "https://${gitlabGroup}.gitlab.io/${gitlabRepositoryName}/snapshot/master/${archivesBaseName}-dev.jar"
it.iconBase64Provider = {
def file = new File(sourceSets.main.resources.srcDirs[0], it)
if (file.exists()) {
def contentType = file.name.endsWith(".svg") ? "svg+xml" : "png"
return "data:image/" + contentType + ";base64," + Base64.getEncoder().encodeToString(Files.readAllBytes(Paths.get(file.toURI())));
}
}
it.addPlugin("$archivesBaseName-dev.jar", project.josm.manifest.createJosmPluginJarManifest(), new URL(pluginDownloadUrl))
}
}
project.afterEvaluate {
publishing {
publications {
plugin(MavenPublication) {
groupId = "org.openstreetmap.josm.plugins"
artifactId = archivesBaseName
version = project.version
from components.java
}
}
}
}
def ciJobToken = System.getenv("CI_JOB_TOKEN")
def projectId = System.getenv("CI_PROJECT_ID")
if (ciJobToken != null && projectId!= null) {
publishing.repositories.maven {
url = "https://gitlab.com/api/v4/projects/$projectId/packages/maven"
name = "gitlab"
credentials(HttpHeaderCredentials.class) {
name = "Job-Token"
value = ciJobToken
}
authentication {
create("auth", HttpHeaderAuthentication.class)
}
}
}
sonarqube {
properties {
property "sonar.organization", "mapwithai"
property "sonar.projectKey", "mapwithai"
property "sonar.forceAuthentication", "true"
property "sonar.host.url", "https://sonarcloud.io"
property "sonar.projectDescription", properties.get("plugin.description")
property "sonar.projectVersion", project.version
property "sonar.sources", ["src"]
}
}