Newer
Older
import java.text.SimpleDateFormat
plugins {
id 'java'
id 'idea'

Griefed
committed
id 'maven-publish'
}
group 'de.griefed'
//noinspection GroovyUnusedAssignment
sourceCompatibility = targetCompatibility = '1.8'
sourceSets {
//noinspection GroovyAssignabilityCheck
main {
java {
srcDirs = ['src/main/java']
}
//noinspection GroovyAssignabilityCheck
resources {
srcDirs = ['src/main/resources']
}
}
test {
java {
srcDirs = ['src/test/java']
}
//noinspection GroovyAssignabilityCheck
resources {
srcDirs = ['src/test/resources']
}
}
}
repositories {
mavenCentral()
}
configurations {
embed
implementation.extendsFrom(embed)
}
dependencies {
embed 'com.typesafe:config:1.4.1'
// Testing
testImplementation 'org.mockito:mockito-core:4.1.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
}
test {
useJUnitPlatform()
// Mention test result in logs
testLogging {
events "passed",
"skipped",
"failed"
}
}
// Include specific files in resources folder, like the license and readme.
tasks.register('about', Copy) {
dependsOn tasks.named('clean')
from layout.projectDirectory.file("LICENSE") into layout.projectDirectory.dir("src/main/resources")
from layout.projectDirectory.file("README.md") into layout.projectDirectory.dir("src/main/resources")
}
tasks.withType(Javadoc) {
options.addStringOption('encoding', 'UTF-8')
}
javadoc {
options.memberLevel = JavadocMemberLevel.PRIVATE
classpath = sourceSets.main.runtimeClasspath
}
java {
withSourcesJar()
withJavadocJar()
}
jar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from {
configurations.embed.findAll { it.name.endsWith('jar') }.collect { zipTree(it) }
}
//noinspection GroovyAssignabilityCheck
manifest {
attributes(
"Main-Class" : "de.griefed.serverpackcreatoraddonexample.Main",
"Class-Path" : configurations.embed.findAll { it.name.endsWith('jar') }.collect { zipTree(it) },
"Description" : "Example addon for ServerPackCreator",
"Built-By" : System.getProperty("user.name"),
"Build-Timestamp": new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(new Date()),
"Created-By" : "Gradle ${gradle.gradleVersion}",
"Build-Jdk" : "${System.getProperty('java.version')} (${System.getProperty('java.vendor')} ${System.getProperty('java.vm.version')})",
"Build-OS" : "${System.getProperty('os.name')} ${System.getProperty('os.arch')} ${System.getProperty('os.version')}",
)
}
exclude (
'META-INF/org',
'META-INF/org/**',
'META-INF/versions',
'META-INF/versions/**',
'META-INF/DEPENDENCIES',
'META-INF/LICENSE',
'META-INF/NOTICE',
'META-INF/CHANGES',
'META-INF/LICENSE.txt',
'META-INF/NOTICE.txt',
'META-INF/README.md',
'Log4j-**'
)

Griefed
committed
}
// Publish the package with passed version to GHPR. Use ./gradlew -Pversion=${NEW_VERSION} publish, for example.
publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/Griefed/serverpackcreatorexampleaddon")
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
}
publications {
//noinspection GroovyAssignabilityCheck
gpr(MavenPublication) {
//noinspection GroovyAssignabilityCheck
artifactId='serverpackcreatorexampleaddon'
//noinspection GroovyAssignabilityCheck
from (components.java)
}
}