forked from natanbc/lavadsp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle
129 lines (107 loc) · 3.14 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
121
122
123
124
125
126
127
128
129
plugins {
id 'java-library'
id 'maven-publish'
id 'com.github.johnrengelman.shadow' version '6.1.0'
}
archivesBaseName = 'lavadsp'
group 'dev.arbjerg'
def (versionStr, isSnapshot) = getGitVersion()
version versionStr
println "Version: " + versionStr
sourceCompatibility = 11
targetCompatibility = 11
repositories {
jcenter()
maven {
url "https://maven.arbjerg.dev/releases"
}
}
dependencies {
implementation 'org.slf4j:slf4j-api:1.7.30'
implementation 'dev.arbjerg:native-loader:0.0.1'
compileOnly 'com.sedmelluq:lavaplayer:1.3.66'
testImplementation 'com.sedmelluq:lavaplayer:1.3.66'
testImplementation 'ch.qos.logback:logback-classic:1.2.3'
}
import org.apache.tools.ant.filters.ReplaceTokens
task sourcesForRelease(type: Copy) {
from 'src/main/java'
into 'build/filteredSrc'
filter(ReplaceTokens, tokens: [
VERSION: version ?: 'dev',
COMMIT_HASH: getCommitHash()
])
}
compileJava {
source = sourcesForRelease.destinationDir
classpath = sourceSets.main.compileClasspath
options.encoding = 'UTF-8'
dependsOn sourcesForRelease
}
jar {
manifest {
attributes 'Implementation-Version': archiveVersion ?: 'dev'
}
}
shadowJar {
archiveClassifier = "withDependencies"
}
task sourcesJar(type: Jar, dependsOn: classes) {
archiveClassifier = 'sources'
from "${buildDir}/filteredSrc"
}
task javadocJar(type: Jar, dependsOn: javadoc) {
archiveClassifier = 'javadoc'
from javadoc.destinationDir
}
def getGitVersion() {
def versionStr = new ByteArrayOutputStream()
def result = exec {
standardOutput versionStr
ignoreExitValue true
commandLine "git", "describe", "--exact-match", "--tags"
}
if (result.exitValue == 0) {
return [versionStr.toString().trim(), false]
}
versionStr = new ByteArrayOutputStream()
result = exec {
standardOutput versionStr
ignoreExitValue true
commandLine "git", "rev-parse", "--short", "HEAD"
}
if (result.exitValue != 0) {
throw new GradleException("Failed to get git version")
}
return [versionStr.toString().trim(), true]
}
static def getCommitHash() {
def p = Runtime.getRuntime().exec("git rev-parse HEAD")
p.waitFor()
p.getIn().text.trim()
}
def isMavenDefined = findProperty("MAVEN_USERNAME") != null && findProperty("MAVEN_PASSWORD") != null
publishing {
publications {
maven(MavenPublication) {
from components.java
}
}
if (isMavenDefined) {
System.out.println("Publishing to Maven Repo")
repositories {
def snapshots = "https://maven.arbjerg.dev/snapshots"
def releases = "https://maven.arbjerg.dev/releases"
maven {
name = "Reposilite"
url = isSnapshot ? snapshots : releases
credentials {
username = findProperty("MAVEN_USERNAME")
password = findProperty("MAVEN_PASSWORD")
}
}
}
} else {
System.out.println("Maven credentials not found, not publishing to Maven Repo")
}
}