-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.gradle
120 lines (102 loc) · 3.17 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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
plugins {
id 'java-library'
id 'eclipse'
id 'maven-publish'
id ('com.gradleup.shadow') version "8.3.3"
}
repositories {
mavenCentral()
maven {
url "https://repo.spongepowered.org/maven/"
}
maven {
url "https://maven.fabricmc.net/"
}
mavenLocal()
}
sourceCompatibility = '17'
targetCompatibility = '17'
version = providerVersion
group = "com.wildermods"
archivesBaseName = "provider"
dependencies {
compileOnly libs.fabric.loader
//mixin requirements:
compileOnly libs.mixin
compileOnly libs.asm
compileOnly libs.asm.analysis
compileOnly libs.asm.commons
compileOnly libs.asm.tree
compileOnly libs.asm.util
implementation(libs.commons.lang) {
transitive = false
}
}
jar {
manifest {
attributes(
'Main-Class': 'net.fabricmc.loader.impl.launch.knot.KnotClient',
'Class-Path': configurations.runtimeClasspath.collect { it.getName() }.join(' '),
'Multi-Release': 'true'
)
}
}
tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
exclude '**/license.txt'
exclude '**/license'
exclude '**/notice.txt'
exclude '**/notice'
exclude '**/LICENSE.txt'
exclude '**/LICENSE'
exclude '**/NOTICE.txt'
exclude '**/NOTICE'
finalizedBy sourceJar
}
ext.mavenLocalUrl = repositories.mavenLocal().url.toString()
task sourceJar(type: Jar) {
from sourceSets.main.allSource
archiveClassifier.set('sources')
}
tasks.register('checkArtifactExists') {
doLast {
def repoUrl = project.hasProperty('mavenRepoUrl') ? project.mavenRepoUrl : mavenLocalUrl
def artifactPath = "${repoUrl}/${project.group.replace('.', '/')}/${project.archivesBaseName}/${project.version}/${project.archivesBaseName}-${project.version}.jar"
logger.lifecycle("Checking if artifact exists at: $artifactPath")
if (artifactPath.startsWith('file:/')) {
// Handle file URLs
def file = new File(new URI(artifactPath))
if (file.exists()) {
throw new IllegalStateException("Artifact '${project.group}:${project.archivesBaseName}:${project.version}' already exists. Publishing aborted.")
}
} else {
// Handle HTTP URLs
def url = new URL(artifactPath)
def connection = url.openConnection()
connection.setRequestMethod('HEAD')
if (connection.responseCode == 200) {
throw new IllegalStateException("Artifact '${project.group}:${project.archivesBaseName}:${project.version}' already exists. Publishing aborted.")
}
}
logger.lifecycle("Artifact does not exist, proceeding with publish.")
}
}
tasks.named('publish') {
dependsOn 'checkArtifactExists'
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
groupId = project.group
artifactId = project.archivesBaseName
version = project.version
// Attach sources JAR to the publication
artifact sourceJar
}
}
repositories {
maven {
url = uri(project.hasProperty('mavenRepoUrl') ? project.mavenRepoUrl : mavenLocalUrl) // Default to mavenLocal if no custom URL is provided
}
}
}