1- import java.net.URI
1+ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
2+ import org.gradle.initialization.Environment.Properties
23
4+ // The project's information.
35group = " net.cameronbowe" // The project's group.
46version = " 1.0.0" // The project's version.
57description = " A utility to access Vouchley's API with ease." // The project's description.
@@ -24,54 +26,71 @@ dependencies {
2426 implementation(" org.apache.httpcomponents" , " httpclient" , " 4.5.13" ) // Implement apache http client (for http requests).
2527}
2628
27- // The publishing to maven.
29+ // The tasks.
30+ tasks {
31+
32+ // The without dependencies jar creation task.
33+ task(" withoutDepends" , type = Jar ::class ) {
34+ from(sourceSets.main.get().allSource) // Add the main sources.
35+ archiveClassifier.set(" withoutDepends" ) // Set the classifier.
36+ archiveFileName.set(" ${project.name} -${project.version} -without-depends.jar" ) // Set the file name.
37+ }
38+
39+ // The with dependencies jar creation task.
40+ task(" withDepends" , type = ShadowJar ::class ) {
41+ from(sourceSets.main.get().allSource) // Add the main sources.
42+ archiveClassifier.set(" withDepends" ) // Set the classifier.
43+ configurations = listOf (project.configurations.runtimeClasspath.get()) // Set the configurations.
44+ archiveFileName.set(" ${project.name} -${project.version} -with-depends.jar" ) // Set the archive file name.
45+ relocate(" com.google.gson" , " net.cameronbowe.relocated.com.google.gson" ) // Relocate gson (so it doesn't conflict with other plugins).
46+ relocate(" org.apache" , " net.cameronbowe.relocated.org.apache" ) // Relocate apache (so it doesn't conflict with other plugins).
47+ exclude(" mozilla/**" , " META-INF/**" , " module-info.class" ) // Exclude some stuff.
48+ }
49+
50+ }
51+
52+ // The publishing to my software repository.
2853publishing {
2954
30- // The publishing repository .
55+ // The publishing repositories (where to publish) .
3156 repositories {
32-
33- // Add the Maven Central repository.
3457 maven {
35- url = uri(" https://s01.oss.sonatype.org/content/repositories/releases/" ) // The sonatype repository.
36- credentials {
37- username = project.findProperty(" ossrhUsername" )?.toString()
38- password = project.findProperty(" ossrhPassword" )?.toString()
58+ name = " net.cameronbowe" // The name of the repository.
59+ url = uri(" https://software.cameronbowe.net/public" ) // The URL of the repository.
60+ authentication { create<BasicAuthentication >(" basic" ) } // The authentication of the repository.
61+ credentials(PasswordCredentials ::class ) { // The credentials of the repository.
62+ username = findProperty(" softwareRepositoryUsername" ) as String? // The username of the repository.
63+ password = findProperty(" softwareRepositoryPassword" ) as String? // The password of the repository.
3964 }
4065 }
41-
4266 }
4367
4468 // The publishing publications (what to publish).
4569 publications {
4670
47- // The maven java publication.
48- register(" mavenJava" , MavenPublication ::class ) {
49- artifact(tasks.named(" shadowJar" ).get()) { classifier = " all" } // Publish the shadow jar.
71+ // The without dependencies publication.
72+ create<MavenPublication >(" withoutDepends" ) {
73+ artifactId = project.name // Set the artifact ID.
74+ groupId = project.group.toString() // Set the group ID.
75+ version = project.version.toString() // Set the version.
76+ artifact(tasks[" withoutDepends" ]) // Set the artifact.
77+ }
78+
79+ // The with dependencies publication.
80+ create<MavenPublication >(" withDepends" ) { // Create a maven publication.
81+ artifactId = project.name // Set the artifact ID.
82+ groupId = project.group.toString() // Set the group ID.
83+ version = project.version.toString() // Set the version.
84+ artifact(tasks[" withDepends" ]) // Set the artifact.
5085 }
5186
5287 }
88+
5389}
5490
55- // The signing ( of the maven publication) .
91+ // The signing of the publications .
5692signing {
57- sign(publishing.publications[" mavenJava" ]) // Sign the maven publication.
58- sign(configurations.archives.get()) // Sign the archives.
5993 useGpgCmd() // Use the gpg command.
60- }
61-
62- // Compilation.
63- tasks {
64-
65- // Handle java compilation.
66- compileJava { // On java compilation.
67- options.encoding = " UTF-8" // Make sure text is UTF-8 (stuff bugs out otherwise).
68- }
69-
70- // Handle shadow jar (shading/relocation).
71- shadowJar {
72- relocate(" com.google.gson" , " com.vouchley.relocated.com.google.gson" ) // Relocate gson (so it doesn't conflict with other plugins).
73- relocate(" org.apache.http" , " com.vouchley.relocated.apache.http" ) // Relocate apache http (so it doesn't conflict with other plugins).
74- exclude(" **/*.txt" , " **./META-INF/*" ) // Exclude gibberish files.
75- }
76-
94+ sign(publishing.publications[" withoutDepends" ]) // Sign the without dependencies publication.
95+ sign(publishing.publications[" withDepends" ]) // Sign the with dependencies publication.
7796}
0 commit comments