1+ import com.github.jengelman.gradle.plugins.shadow.ShadowExtension
2+ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
3+
4+ plugins {
5+ `maven- publish`
6+ id(" io.github.gradle-nexus.publish-plugin" ) version " 1.1.0"
7+ id(" com.github.johnrengelman.shadow" ) version " 7.1.2"
8+ id(" cl.franciscosolis.blossom-extended" ) version " 1.3.1"
9+
10+ kotlin(" jvm" ) version " 1.8.10"
11+ id(" org.jetbrains.dokka" ) version " 1.7.20"
12+ }
13+
14+ val env = project.rootProject.file(" .env" ).let { file ->
15+ if (file.exists()) file.readLines().filter { it.isNotBlank() && ! it.startsWith(" #" ) && it.split(" =" ).size == 2 }.associate { it.split(" =" )[0 ] to it.split(" =" )[1 ] } else emptyMap()
16+ }.toMutableMap().apply { putAll(System .getenv()) }
17+
18+ val projectVersion = env[" VERSION" ] ? : " 0.2.0-SNAPSHOT"
19+
20+ group = " xyz.theprogramsrc"
21+ version = projectVersion
22+ description = " File configurations and utils for the SimpleCore API"
23+
24+ repositories {
25+ mavenLocal()
26+ mavenCentral()
27+
28+ maven(" https://oss.sonatype.org/content/repositories/snapshots/" )
29+ maven(" https://oss.sonatype.org/content/repositories/releases/" )
30+ maven(" https://oss.sonatype.org/content/groups/public/" )
31+ maven(" https://hub.spigotmc.org/nexus/content/repositories/snapshots/" )
32+ maven(" https://repo.codemc.org/repository/maven-public/" )
33+ maven(" https://jitpack.io/" )
34+ }
35+
36+ dependencies {
37+ compileOnly(" xyz.theprogramsrc:simplecoreapi:0.6.2-SNAPSHOT" )
38+
39+ implementation(" me.carleslc.Simple-YAML:Simple-Yaml:1.8.3" )
40+
41+ testImplementation(" org.junit.jupiter:junit-jupiter:5.9.2" )
42+ }
43+
44+
45+ tasks {
46+ named<ShadowJar >(" shadowJar" ) {
47+ relocate(" org.simpleyaml" , " xyz.theprogramsrc.filesmodule.libs.simpleyaml" )
48+ relocate(" org.yaml.snakeyaml" , " xyz.theprogramsrc.filesmodule.libs.snakeyaml" )
49+
50+ mergeServiceFiles()
51+ exclude(" **/*.kotlin_metadata" )
52+ exclude(" **/*.kotlin_builtins" )
53+
54+ archiveBaseName.set(" FilesModule" )
55+ archiveClassifier.set(" " )
56+ }
57+
58+ test {
59+ useJUnitPlatform()
60+ }
61+
62+ java {
63+ sourceCompatibility = JavaVersion .VERSION_11
64+ targetCompatibility = JavaVersion .VERSION_11
65+ withSourcesJar()
66+ withJavadocJar()
67+ }
68+
69+ compileKotlin {
70+ kotlinOptions {
71+ jvmTarget = " 11"
72+ }
73+ }
74+
75+ compileTestKotlin {
76+ kotlinOptions {
77+ jvmTarget = " 11"
78+ }
79+ }
80+
81+ compileJava {
82+ options.encoding = " UTF-8"
83+ }
84+
85+ jar {
86+ duplicatesStrategy = DuplicatesStrategy .EXCLUDE
87+ }
88+
89+ copy {
90+ duplicatesStrategy = DuplicatesStrategy .EXCLUDE
91+ }
92+
93+ dokkaHtml {
94+ outputDirectory.set(file(project.buildDir.absolutePath + " /dokka" ))
95+ }
96+ }
97+
98+ configurations {
99+ testImplementation {
100+ extendsFrom(configurations.compileOnly.get())
101+ }
102+ }
103+
104+ val dokkaJavadocJar by tasks.register<Jar >(" dokkaJavadocJar" ) {
105+ dependsOn(tasks.dokkaJavadoc, tasks.dokkaHtml)
106+ from(tasks.dokkaJavadoc.flatMap { it.outputDirectory })
107+ archiveClassifier.set(" javadoc" )
108+ }
109+
110+ publishing {
111+ repositories {
112+ if (env[" ENV" ] == " prod" ) {
113+ if (env.containsKey(" GITHUB_ACTOR" ) && env.containsKey(" GITHUB_TOKEN" )) {
114+ maven {
115+ name = " GithubPackages"
116+ url = uri(" https://maven.pkg.github.com/TheProgramSrc/SimpleCore-FilesModule" )
117+ credentials {
118+ username = env[" GITHUB_ACTOR" ]
119+ password = env[" GITHUB_TOKEN" ]
120+ }
121+ }
122+ }
123+ } else {
124+ mavenLocal()
125+ }
126+ }
127+
128+ publications {
129+ create<MavenPublication >(" shadow" ) {
130+ project.extensions.configure<ShadowExtension > {
131+ artifactId = rootProject.name.lowercase()
132+
133+ component(this @create)
134+ artifact(dokkaJavadocJar)
135+ artifact(tasks.kotlinSourcesJar)
136+
137+ pom {
138+ name.set(rootProject.name)
139+ description.set(project.description)
140+ url.set(" https://github.com/TheProgramSrc/SimpleCore-FilesModule" )
141+
142+ licenses {
143+ license {
144+ name.set(" GNU GPL v3" )
145+ url.set(" https://github.com/TheProgramSrc/SimpleCore-FilesModule/blob/master/LICENSE" )
146+ }
147+ }
148+
149+ developers {
150+ developer {
151+ id.set(" ImFran" )
152+ name.set(" Francisco Solis" )
153+ email.set(" imfran@duck.com" )
154+ }
155+ }
156+
157+ scm {
158+ url.set(" https://github.com/TheProgramSrc/SimpleCore-FilesModule" )
159+ }
160+ }
161+ }
162+ }
163+ }
164+ }
165+
166+ nexusPublishing {
167+ repositories {
168+ sonatype {
169+ nexusUrl.set(uri(" https://s01.oss.sonatype.org/service/local/" ))
170+ snapshotRepositoryUrl.set(uri(" https://s01.oss.sonatype.org/content/repositories/snapshots/" ))
171+
172+ username.set(env[" SONATYPE_USERNAME" ])
173+ password.set(env[" SONATYPE_PASSWORD" ])
174+ }
175+ }
176+ }
177+
178+ tasks.withType<PublishToMavenRepository > {
179+ dependsOn(tasks.test, tasks.kotlinSourcesJar, dokkaJavadocJar, tasks.jar, tasks.shadowJar)
180+ }
181+
182+ tasks.withType<PublishToMavenLocal > {
183+ dependsOn(tasks.test, tasks.kotlinSourcesJar, tasks.jar, dokkaJavadocJar, tasks.shadowJar)
184+ }
0 commit comments