aboutsummaryrefslogtreecommitdiffstats
path: root/buildSrc/src/main/kotlin/refinery-jmh.gradle.kts
blob: 11888b59614d244c84faccb9403965802bbcee22 (plain) (blame)
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
import org.gradle.accessors.dm.LibrariesForLibs
import org.gradle.plugins.ide.eclipse.model.EclipseModel
import org.sonarqube.gradle.SonarExtension
import tools.refinery.buildsrc.EclipseUtils
import tools.refinery.buildsrc.SonarPropertiesUtils

apply(plugin = "refinery-java-conventions")
apply(plugin = "refinery-sonarqube")

val sourceSets = the<SourceSetContainer>()

val main: SourceSet by sourceSets.getting

val test: SourceSet by sourceSets.getting

val jmh: SourceSet by sourceSets.creating {
	compileClasspath += main.output
	runtimeClasspath += main.output
	// Allow using test classes in benchmarks for now.
	compileClasspath += test.output
	runtimeClasspath += test.output
}

val jmhImplementation: Configuration by configurations.getting {
	extendsFrom(configurations["implementation"], configurations["testImplementation"])
}

val jmhAnnotationProcessor: Configuration by configurations.getting

configurations["jmhRuntimeOnly"].extendsFrom(configurations["runtimeOnly"], configurations["testRuntimeOnly"])

val libs = the<LibrariesForLibs>()

dependencies {
	jmhImplementation(libs.jmh.core)
	jmhAnnotationProcessor(libs.jmh.annprocess)
}

tasks.register("jmh", JavaExec::class) {
	dependsOn(tasks.named("jmhClasses"))
	mainClass.set("org.openjdk.jmh.Main")
	classpath = jmh.runtimeClasspath
}

EclipseUtils.patchClasspathEntries(the<EclipseModel>()) { entry ->
	// Workaround from https://github.com/gradle/gradle/issues/4802#issuecomment-407902081
	if (entry.entryAttributes["gradle_scope"] == "jmh") {
		// Allow test helper classes to be used in benchmarks from Eclipse
		// and do not expose JMH dependencies to the main source code.
		entry.entryAttributes["test"] = true
	} else {
		EclipseUtils.patchGradleUsedByScope(entry) { usedBy ->
			if (listOf("main", "test", "testFixtures").any { e -> usedBy.contains(e) }) {
				// main and test sources are also used by jmh sources.
				usedBy += "jmh"
			}
		}
	}
}

the<SonarExtension>().properties {
	SonarPropertiesUtils.addToList(properties, "sonar.tests", "src/jmh/java")
}