Changeset View
Changeset View
Standalone View
Standalone View
build.gradle
/* | /* | ||||
* Copyright 2019 Wildfyre.net | * Copyright 2019 Wildfyre.net | ||||
* | * | ||||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
* You may obtain a copy of the License at | * You may obtain a copy of the License at | ||||
* | * | ||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | * | ||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
* See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||
* limitations under the License. | * limitations under the License. | ||||
*/ | */ | ||||
//region Plugins | |||||
import org.gradle.internal.jvm.Jvm | import org.gradle.internal.jvm.Jvm | ||||
plugins { | plugins { | ||||
id 'java' | id 'java' | ||||
id 'findbugs' | id 'findbugs' | ||||
id 'signing' // To GPG-sign the archives that will be published. | id 'signing' // To GPG-sign the archives that will be published. | ||||
id 'maven' // To export to Maven | id 'maven' // To export to Maven | ||||
id 'io.codearte.nexus-staging' version '0.11.0' // Confirm publication to MavenCentral | id 'io.codearte.nexus-staging' version '0.11.0' // Confirm publication to MavenCentral | ||||
id 'org.jetbrains.kotlin.jvm' version '1.2.70' | id 'org.jetbrains.kotlin.jvm' version '1.2.70' | ||||
id 'org.jetbrains.dokka' version '0.9.17' | id 'org.jetbrains.dokka' version '0.9.17' | ||||
id 'jacoco' // Code coverage | |||||
} | |||||
repositories { | |||||
mavenCentral() | |||||
} | } | ||||
//endregion | |||||
//region Version handling | |||||
group 'net.wildfyre' | group 'net.wildfyre' | ||||
getVersion() | getVersion() | ||||
sourceCompatibility = 1.8 | sourceCompatibility = 1.8 | ||||
targetCompatibility = 1.8 | targetCompatibility = 1.8 | ||||
void getVersion(){ | void getVersion(){ | ||||
def stdout = new ByteArrayOutputStream() | def stdout = new ByteArrayOutputStream() | ||||
exec { | exec { | ||||
commandLine 'git', 'describe', '--tags', '--candidates=30', '--dirty=-SNAPSHOT' | commandLine 'git', 'describe', '--tags', '--candidates=30', '--dirty=-SNAPSHOT' | ||||
standardOutput = stdout | standardOutput = stdout | ||||
} | } | ||||
version stdout | version stdout | ||||
.toString()[1..-2] // Remove the \n character at the end of the command and the 'v' | .toString()[1..-2] // Remove the \n character at the end of the command and the 'v' | ||||
.replaceFirst("-\\d+-", "-") // Remove the number of commits | .replaceFirst("-\\d+-", "-") // Remove the number of commits | ||||
if ( !project.hasProperty('skipGetVersion') ) | if ( !project.hasProperty('skipGetVersion') ) | ||||
println "Detected project version: " + version | println "Detected project version: " + version | ||||
} | } | ||||
repositories { | //endregion | ||||
mavenCentral() | //region Jar & FatJar | ||||
} | |||||
configurations { | configurations { | ||||
fatJar | fatJar | ||||
} | } | ||||
jar { | jar { | ||||
doFirst { | doFirst { | ||||
from { configurations.fatJar.collect { it.isDirectory() ? it : zipTree(it) } } | from { configurations.fatJar.collect { it.isDirectory() ? it : zipTree(it) } } | ||||
} | } | ||||
} | } | ||||
//enregion | |||||
dependencies { | dependencies { | ||||
testCompile group: 'junit', name: 'junit', version: '4.12' | testCompile group: 'junit', name: 'junit', version: '4.12' | ||||
implementation group: 'com.eclipsesource.minimal-json', name: 'minimal-json', version: '0.9.5' | implementation group: 'com.eclipsesource.minimal-json', name: 'minimal-json', version: '0.9.5' | ||||
fatJar group: 'com.eclipsesource.minimal-json', name: 'minimal-json', version: '0.9.5' | fatJar group: 'com.eclipsesource.minimal-json', name: 'minimal-json', version: '0.9.5' | ||||
compile 'com.google.code.findbugs:annotations:3.0.1' | compile 'com.google.code.findbugs:annotations:3.0.1' | ||||
compile 'com.google.code.findbugs:jsr305:3.0.1' | compile 'com.google.code.findbugs:jsr305:3.0.1' | ||||
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8" | compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8" | ||||
} | } | ||||
javadoc { | javadoc { | ||||
options { | options { | ||||
addStringOption('source', '8') | addStringOption('source', '8') | ||||
addStringOption('link', "https://docs.oracle.com/javase/8/docs/api/") | addStringOption('link', "https://docs.oracle.com/javase/8/docs/api/") | ||||
//addBooleanOption('html5', true) Only in Java 9+, breaks in Java 8 | //addBooleanOption('html5', true) Only in Java 9+, breaks in Java 8 | ||||
} | } | ||||
} | } | ||||
test { | |||||
// Using less cores than available, because JUnit needs some to work | |||||
def runners = Runtime.runtime.availableProcessors() - 2 | |||||
maxParallelForks = runners > 0 ? runners : 1 | |||||
} | |||||
tasks.withType(FindBugs) { | tasks.withType(FindBugs) { | ||||
reports { | reports { | ||||
xml.enabled = false | xml.enabled = false | ||||
html.enabled = true | html.enabled = true | ||||
} | } | ||||
} | } | ||||
findbugsMain { | findbugsMain { | ||||
classpath += files Jvm.current().getJavaHome() | classpath += files Jvm.current().getJavaHome() | ||||
} | } | ||||
findbugsTest { | findbugsTest { | ||||
classpath += files Jvm.current().getJavaHome() | classpath += files Jvm.current().getJavaHome() | ||||
} | } | ||||
// Removes the directories out/ (created by IntelliJ) and wildfyre.net/ (created by the maven plugin) when calling | // Removes the directories out/ (created by IntelliJ) and wildfyre.net/ (created by the maven plugin) when calling | ||||
// 'gradle clean'. | // 'gradle clean'. | ||||
clean { | clean { | ||||
delete "${rootDir}/out" | delete "${rootDir}/out" | ||||
delete "${rootDir}/wildfyre.net" | delete "${rootDir}/wildfyre.net" | ||||
delete "${rootDir}/http/out" | delete "${rootDir}/http/out" | ||||
delete "${rootDir}/cache/out" | delete "${rootDir}/cache/out" | ||||
} | } | ||||
//region Code coverage | |||||
jacoco { | |||||
toolVersion = "0.8.4" | |||||
} | |||||
jacocoTestReport { | |||||
reports { | |||||
xml.enabled false | |||||
csv.enabled true | |||||
html.enabled true | |||||
html.destination file("${buildDir}/jacocoHtml") | |||||
} | |||||
} | |||||
jacocoTestCoverageVerification { | |||||
violationRules { | |||||
rule { | |||||
limit { | |||||
minimum = 0.5 | |||||
} | |||||
} | |||||
} | |||||
} | |||||
jacocoTestCoverageVerification.dependsOn(test) | |||||
jacocoTestCoverageVerification.finalizedBy(jacocoTestReport) | |||||
task coverage {} | |||||
coverage.dependsOn(jacocoTestCoverageVerification) | |||||
//endregion | |||||
//region Check the API | |||||
task testAPI(type: Exec) { | task testAPI(type: Exec) { | ||||
if (org.gradle.internal.os.OperatingSystem.current().isLinux()) { | if (org.gradle.internal.os.OperatingSystem.current().isLinux()) { | ||||
// Checking if the API is running but not launching it, | // Checking if the API is running but not launching it, | ||||
// because it needs to run in another terminal so the log is visible. | // because it needs to run in another terminal so the log is visible. | ||||
commandLine './api.sh', '--norun' | commandLine './api.sh', '--norun' | ||||
} else { | } else { | ||||
// The following two lines are included here because they are in the script | // The following two lines are included here because they are in the script | ||||
// but NEED to be executed for platforms that don't support the script too. | // but NEED to be executed for platforms that don't support the script too. | ||||
// They cannot be here for all platforms because this task never executes the script. | // They cannot be here for all platforms because this task never executes the script. | ||||
commandLine 'git', 'submodule', 'init' | commandLine 'git', 'submodule', 'init' | ||||
commandLine 'git', 'submodule', 'update' | commandLine 'git', 'submodule', 'update' | ||||
println("Cannot automatically check if the API is running.") | println("Cannot automatically check if the API is running.") | ||||
} | } | ||||
} | } | ||||
test.dependsOn(testAPI) // The API is needed for testing purposes only | test.dependsOn(testAPI) // The API is needed for testing purposes only | ||||
//endregion | |||||
//region Deployment | |||||
// Javadoc task as seen at https://central.sonatype.org/pages/gradle.html | // Javadoc task as seen at https://central.sonatype.org/pages/gradle.html | ||||
// Needed for publishing | // Needed for publishing | ||||
task javadocJar(type: Jar) { | task javadocJar(type: Jar) { | ||||
classifier = 'javadoc' | classifier = 'javadoc' | ||||
from javadoc | from javadoc | ||||
} | } | ||||
// Sources task as seen at https://central.sonatype.org/pages/gradle.html | // Sources task as seen at https://central.sonatype.org/pages/gradle.html | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | repositories { | ||||
name 'Ivan Canet' | name 'Ivan Canet' | ||||
email 'ivan.canet@gmail.com' | email 'ivan.canet@gmail.com' | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
//enregion | |||||
//region Kotlin settings | |||||
compileKotlin { | compileKotlin { | ||||
kotlinOptions { | kotlinOptions { | ||||
jvmTarget = "1.8" | jvmTarget = "1.8" | ||||
} | } | ||||
} | } | ||||
compileTestKotlin { | compileTestKotlin { | ||||
kotlinOptions { | kotlinOptions { | ||||
jvmTarget = "1.8" | jvmTarget = "1.8" | ||||
} | } | ||||
} | } | ||||
dokka { | dokka { | ||||
outputFormat = 'javadoc' | outputFormat = 'javadoc' | ||||
outputDirectory = 'build/docs/dokka' | outputDirectory = 'build/docs/dokka' | ||||
jdkVersion = 8 | jdkVersion = 8 | ||||
includeNonPublic = false | includeNonPublic = false | ||||
reportUndocumented = true | reportUndocumented = true | ||||
linkMapping { | linkMapping { | ||||
dir = "src/" | dir = "src/" | ||||
url = "https://phabricator.wildfyre.net/source/libwf-java/browse/master/src/" | url = "https://phabricator.wildfyre.net/source/libwf-java/browse/master/src/" | ||||
suffix = "\$" | suffix = "\$" | ||||
} | } | ||||
} | } | ||||
task machineReadableTestStatus { | //enregion | ||||
doLast { | |||||
def ret = 0 | |||||
if ( check.state.failure == null ) { | |||||
ret = ret | 0b01 | |||||
} | |||||
if ( test.state.failure == null ) { | |||||
ret = ret | 0b10 | |||||
} | |||||
println ret | |||||
} | |||||
} |