aboutsummaryrefslogtreecommitdiffstats
path: root/buildSrc/src/main/groovy/refinery-jmh.gradle
blob: 1765446388f333ee74bb52922f1a17ba83e94f8c (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
plugins {
	id 'refinery-java-conventions'
	id 'refinery-sonarqube'
}

configurations {
	jmh {
		extendsFrom implementation
	}
}

sourceSets {
	jmh {
		java.srcDirs = ['src/jmh/java']
        resources.srcDirs = ['src/jmh/resources']
        compileClasspath += sourceSets.main.runtimeClasspath
        compileClasspath += sourceSets.test.runtimeClasspath
	}
}

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

tasks.register('jmh', JavaExec) {
	dependsOn tasks.named('jmhClasses')
    main = 'org.openjdk.jmh.Main'
    classpath = sourceSets.jmh.compileClasspath + sourceSets.jmh.runtimeClasspath
}

eclipse.classpath.file.whenMerged { classpath ->
	for (entry in classpath.entries) {
		if (entry in org.gradle.plugins.ide.eclipse.model.AbstractClasspathEntry) {
			// 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 {
				// Workaround based on
				// https://discuss.gradle.org/t/gradle-used-by-scope-not-correctly-generated-when-the-java-test-fixtures-plugin-is-used/39935/2
				def usedBy = new LinkedHashSet(
					Arrays.asList((entry.entryAttributes['gradle_used_by_scope'] ?: '').split(','))
				)
				if (['main', 'test', 'testFixtures'].any { e -> usedBy.contains(e) }) {
					// main and test sources are also used by jmh sources.
					usedBy += 'jmh'
				}
				entry.entryAttributes['gradle_used_by_scope'] = usedBy.join(',')
			}
		}
	}
}

sonarqube.properties {
	properties['sonar.tests'] += [
		'src/jmh/java',
	]
}