-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle
194 lines (167 loc) · 6.83 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
// Define the Java versions you want to build for
def javaVersions = [8, 11, 21]
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'signing'
// to build call ./gradlew --console=plain clean jar8 jar11 jar21
// to publish call gradle jar8 jar11 jar21 publish
repositories {
mavenCentral()
}
dependencies {
implementation 'net.bytebuddy:byte-buddy:1.14.6'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.0'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.10.0'
testImplementation 'org.skyscreamer:jsonassert:1.5.1'
}
println "Registering tasks for ${javaVersions}"
javadoc.options.addStringOption('Xdoclint:none', '-quiet')
test {
useJUnitPlatform()
// Show standard output and standard error of the test.
testLogging {
events "passed", "skipped", "failed"
showStandardStreams = true
// Optionally, include more details on failures
exceptionFormat = 'full' // Options: 'full', 'short'
}
// Gradle often suppresses output; this will always show it on console
testLogging {
showExceptions true
showCauses true
showStackTraces true
}
// Force all output to be shown immediately
outputs.upToDateWhen { false }
}
javaVersions.each { javaVersion ->
def compileTaskName = "compileJava${javaVersion}"
def processResourcesTaskName = "processResources${javaVersion}"
def classesDir = file("$buildDir/classes/java${javaVersion}/main")
def resourcesDir = file("$buildDir/resources/java${javaVersion}/main")
def jarTaskName = "jar${javaVersion}"
def classesTaskName = "classes${javaVersion}"
def javaDocTaskName = "javadoc${javaVersion}"
def sourcesJavaTaskName="sources${javaVersion}"
def testTaskName = "test${javaVersion}"
// Determine the compiler version to use
def compilerVersion = javaVersion >= 9 ? javaVersion : 11 // Use at least Java 11 compiler
// Sources JAR task
tasks.register(sourcesJavaTaskName, Jar) {
archiveClassifier.set("sources-java${javaVersion}")
from sourceSets.main.allSource
}
// Javadoc JAR task
tasks.register(javaDocTaskName, Jar) {
archiveClassifier.set("javadoc-java${javaVersion}")
from tasks.javadoc
}
// Custom compile task for the specified Java version
tasks.register(compileTaskName, JavaCompile) {
source = sourceSets.main.java
classpath = sourceSets.main.compileClasspath
destinationDirectory = classesDir
options.encoding = 'UTF-8'
options.release = javaVersion
javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(compilerVersion)
}
}
// Custom processResources task for the specified Java version
tasks.register(processResourcesTaskName, Copy) {
from sourceSets.main.resources
into resourcesDir
}
// Custom classes task that depends on compile and processResources
tasks.register(classesTaskName) {
dependsOn compileTaskName, processResourcesTaskName
}
// Custom JAR task for the specified Java version
tasks.register(jarTaskName, Jar) {
dependsOn tasks.named(classesTaskName)
archiveClassifier.set("java${javaVersion}")
from classesDir
from resourcesDir
// Include dependencies in the JAR
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
manifest {
attributes "Main-Class": "com.github.beothorn.agent.MethodInstrumentationAgent"
attributes "Agent-Class": "com.github.beothorn.agent.MethodInstrumentationAgent"
attributes "Premain-Class": "com.github.beothorn.agent.MethodInstrumentationAgent"
attributes "Can-Redefine-Classes": "true"
attributes "Can-Retransform-Classes": "true"
}
}
}
afterEvaluate {
publishing {
publications {
javaVersions.each { javaVersion ->
def publicationName = "maven${javaVersion}"
def jarTaskName = "jar${javaVersion}"
// Create a publication for each Java version
create(publicationName, MavenPublication) {
groupId = 'com.github.beothorn'
artifactId = 'javaFlame'
version = '27.0.0'
// Include the custom JAR
artifact(tasks.named(jarTaskName).get()) {
classifier = "java${javaVersion}"
}
// Include sources and Javadoc JARs
artifact(tasks.named("sources${javaVersion}").get()) {
classifier = "sources-java${javaVersion}"
}
artifact(tasks.named("javadoc${javaVersion}").get()) {
classifier = "javadoc-java${javaVersion}"
}
// POM configuration
pom {
name = 'Javaflame'
description = 'An agent that creates reports for function calls with argument and return values.'
url = 'https://github.com/beothorn/javaflame'
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'beothorn'
name = 'Lucas S'
email = '[email protected]'
}
}
scm {
connection = 'scm:git:[email protected]:beothorn/javaflame.git'
developerConnection = 'scm:git:ssh://[email protected]/beothorn/javaflame.git'
url = 'https://github.com/beothorn/javaflame'
}
}
}
}
}
repositories {
maven {
name = 'OSSRH'
url = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
// Only set credentials if they are present
if (project.hasProperty('ossrhUsername') && project.hasProperty('ossrhPassword')) {
credentials {
username = project.ossrhUsername
password = project.ossrhPassword
}
}
}
}
}
signing {
javaVersions.each { javaVersion ->
def publicationName = "maven${javaVersion}"
sign publishing.publications[publicationName]
}
}
}