-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
143 lines (124 loc) · 3.74 KB
/
Copy pathbuild.gradle
File metadata and controls
143 lines (124 loc) · 3.74 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import groovy.io.FileType
apply plugin: 'java-library'
apply plugin: 'maven-publish'
apply plugin: 'eclipse'
group = 'com.thegamecommunity'
version = "${project.version}"
buildscript {
repositories {
mavenCentral()
maven {
url "https://libraries.minecraft.net"
}
}
}
repositories {
maven {
url "https://libraries.minecraft.net"
}
mavenCentral()
}
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
dependencies {
testImplementation libs.guava.core
testImplementation libs.junit
testImplementation libs.hamcrest
testImplementation libs.mockito.core
testImplementation libs.mockito.junit
testImplementation libs.guava.testlib
testImplementation libs.jmh.core
annotationProcessor libs.jmh.generator
}
task sourcesJar(type: Jar) {
archiveClassifier.set("sources")
from sourceSets.main.allSource
from sourceSets.test.allSource
}
build.dependsOn(sourcesJar)
sourceSets {
main {
java {
srcDirs = ['src/main/java']
}
resources {
srcDirs = ['src/main/resources']
}
}
test {
java {
srcDirs = ['src/test/java']
}
resources {
srcDirs = ['src/test/resources']
}
}
}
test {
testLogging {
events "failed", "skipped"
showStandardStreams = true
showExceptions true
}
}
ext.mavenLocalUrl = repositories.mavenLocal().url.toString()
jar {
manifest {
attributes(
'Class-Path': configurations.runtimeClasspath.collect { it.getName() }.join(' '),
'MixinConfigs': 'mixins.json',
'Main-Class': 'net.fabricmc.loader.impl.launch.knot.KnotClient',
'Specification-Version': 8.0,
'Multi-Release': 'true'
)
}
}
tasks.register('checkArtifactExists') {
doLast {
if (project.hasProperty('force')) {
logger.lifecycle("Skipping artifact existence check due to --force flag.")
return
}
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 sourcesJar
}
}
repositories {
maven {
url = uri(project.hasProperty('mavenRepoUrl') ? project.mavenRepoUrl : mavenLocalUrl) // Default to mavenLocal if no custom URL is provided
}
}
}