aboutsummaryrefslogtreecommitdiffstats
path: root/buildSrc
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2021-11-17 03:06:39 +0100
committerLibravatar Kristóf Marussy <kristof@marussy.com>2021-11-17 03:06:39 +0100
commit720b9e2fb0968905e5a80f6099eab37554a6af58 (patch)
treeb471f4da129efbfa730830a70e0107de852833d7 /buildSrc
parentbuild: use version catalogs (diff)
downloadrefinery-720b9e2fb0968905e5a80f6099eab37554a6af58.tar.gz
refinery-720b9e2fb0968905e5a80f6099eab37554a6af58.tar.zst
refinery-720b9e2fb0968905e5a80f6099eab37554a6af58.zip
build: move scripts into script plugins
Script plugins allow applying other plugins from plugins { } blocks, which simplifies the build script.
Diffstat (limited to 'buildSrc')
-rw-r--r--buildSrc/build.gradle12
-rw-r--r--buildSrc/settings.gradle9
-rw-r--r--buildSrc/src/main/groovy/tools.refinery.java-conventions.gradle45
-rw-r--r--buildSrc/src/main/groovy/tools.refinery.jmh-conventions.gradle58
-rw-r--r--buildSrc/src/main/groovy/tools.refinery.junit-conventions.gradle33
-rw-r--r--buildSrc/src/main/groovy/tools.refinery.mwe2-conventions.gradle16
-rw-r--r--buildSrc/src/main/groovy/tools.refinery.xtend-conventions.gradle37
-rw-r--r--buildSrc/src/main/groovy/tools.refinery.xtext-conventions.gradle21
8 files changed, 231 insertions, 0 deletions
diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle
new file mode 100644
index 00000000..74fe04fb
--- /dev/null
+++ b/buildSrc/build.gradle
@@ -0,0 +1,12 @@
1plugins {
2 id 'groovy-gradle-plugin'
3}
4
5repositories {
6 gradlePluginPortal()
7}
8
9dependencies {
10 implementation libs.sonarqubeGradle
11 implementation libs.xtendGradle
12}
diff --git a/buildSrc/settings.gradle b/buildSrc/settings.gradle
new file mode 100644
index 00000000..794aa2a1
--- /dev/null
+++ b/buildSrc/settings.gradle
@@ -0,0 +1,9 @@
1enableFeaturePreview 'VERSION_CATALOGS'
2
3dependencyResolutionManagement {
4 versionCatalogs {
5 libs {
6 from files('../gradle/libs.versions.toml')
7 }
8 }
9}
diff --git a/buildSrc/src/main/groovy/tools.refinery.java-conventions.gradle b/buildSrc/src/main/groovy/tools.refinery.java-conventions.gradle
new file mode 100644
index 00000000..6bea6e46
--- /dev/null
+++ b/buildSrc/src/main/groovy/tools.refinery.java-conventions.gradle
@@ -0,0 +1,45 @@
1plugins {
2 id 'eclipse'
3}
4
5repositories {
6 mavenCentral()
7 maven {
8 url 'https://repo.eclipse.org/content/groups/releases/'
9 }
10}
11
12sourceCompatibility = '17'
13targetCompatibility = '17'
14
15tasks.named('jar') {
16 manifest {
17 attributes 'Bundle-SymbolicName': project.name
18 }
19}
20
21def generateEclipseSourceFolders = tasks.register('generateEclipseSourceFolders')
22
23tasks.register('prepareEclipse') {
24 dependsOn generateEclipseSourceFolders
25 dependsOn tasks.named('eclipseJdt')
26}
27
28tasks.named('eclipseClasspath') {
29 dependsOn generateEclipseSourceFolders
30}
31
32eclipse {
33 classpath.file.whenMerged {
34 for (entry in entries) {
35 if (entry.path.endsWith('-gen')) {
36 entry.entryAttributes['ignore_optional_problems'] = true
37 }
38 }
39 }
40
41 jdt.file.withProperties { properties ->
42 // Allow @SupperessWarnings to suppress SonarLint warnings
43 properties['org.eclipse.jdt.core.compiler.problem.unhandledWarningToken'] = 'ignore'
44 }
45}
diff --git a/buildSrc/src/main/groovy/tools.refinery.jmh-conventions.gradle b/buildSrc/src/main/groovy/tools.refinery.jmh-conventions.gradle
new file mode 100644
index 00000000..0a82ae4b
--- /dev/null
+++ b/buildSrc/src/main/groovy/tools.refinery.jmh-conventions.gradle
@@ -0,0 +1,58 @@
1plugins {
2 id 'org.sonarqube'
3 id 'tools.refinery.java-conventions'
4}
5
6configurations {
7 jmh {
8 extendsFrom implementation
9 }
10}
11
12sourceSets {
13 jmh {
14 java.srcDirs = ['src/jmh/java']
15 resources.srcDirs = ['src/jmh/resources']
16 compileClasspath += sourceSets.main.runtimeClasspath
17 compileClasspath += sourceSets.test.runtimeClasspath
18 }
19}
20
21dependencies {
22 jmhImplementation libs.jmh.core
23 jmhAnnotationProcessor libs.jmh.annprocess
24}
25
26tasks.register('jmh', JavaExec) {
27 dependsOn tasks.named('jmhClasses')
28 main = 'org.openjdk.jmh.Main'
29 classpath = sourceSets.jmh.compileClasspath + sourceSets.jmh.runtimeClasspath
30}
31
32eclipse.classpath {
33 plusConfigurations += [configurations.jmhCompileClasspath, configurations.jmhRuntimeClasspath]
34
35 file.whenMerged { classpath ->
36 for (entry in classpath.entries) {
37 // Workaround from https://github.com/gradle/gradle/issues/4802#issuecomment-407902081
38 if (entry in org.gradle.plugins.ide.eclipse.model.AbstractClasspathEntry) {
39 def usedBy = (entry.entryAttributes['gradle_used_by_scope'] ?: '').split(',')
40 if (usedBy == ['jmh']) {
41 // Allow test helper classes to be used in benchmarks from Eclipse
42 // and do not expose JMH dependencies to the main source code.
43 entry.entryAttributes['test'] = true
44 } else if ((usedBy.contains('main') || usedBy.contains('test')) && !usedBy.contains('jmh')) {
45 // main and test sources are also used by jmh sources.
46 usedBy += 'jmh'
47 entry.entryAttributes['gradle_used_by_scope'] = usedBy.join(',')
48 }
49 }
50 }
51 }
52}
53
54sonarqube.properties {
55 properties['sonar.tests'] += [
56 'src/jmh/java',
57 ]
58}
diff --git a/buildSrc/src/main/groovy/tools.refinery.junit-conventions.gradle b/buildSrc/src/main/groovy/tools.refinery.junit-conventions.gradle
new file mode 100644
index 00000000..d62207b7
--- /dev/null
+++ b/buildSrc/src/main/groovy/tools.refinery.junit-conventions.gradle
@@ -0,0 +1,33 @@
1plugins {
2 id 'jacoco'
3 id 'tools.refinery.java-conventions'
4}
5
6dependencies {
7 testImplementation libs.hamcrest
8 testImplementation libs.junit.api
9 testRuntimeOnly libs.junit.engine
10 testImplementation libs.junit.params
11 testImplementation libs.mockito.core
12 testImplementation libs.mockito.junit
13}
14
15def jacocoTestReport = tasks.named('jacocoTestReport')
16jacocoTestReport.configure {
17 dependsOn test
18 reports {
19 xml.required = true
20 }
21}
22
23tasks.named('test') {
24 useJUnitPlatform {
25 excludeTags 'slow'
26 }
27 finalizedBy jacocoTestReport
28}
29
30tasks.register('slowTest', Test) {
31 useJUnitPlatform()
32 finalizedBy jacocoTestReport
33}
diff --git a/buildSrc/src/main/groovy/tools.refinery.mwe2-conventions.gradle b/buildSrc/src/main/groovy/tools.refinery.mwe2-conventions.gradle
new file mode 100644
index 00000000..fe213d42
--- /dev/null
+++ b/buildSrc/src/main/groovy/tools.refinery.mwe2-conventions.gradle
@@ -0,0 +1,16 @@
1plugins {
2 id 'eclipse'
3 id 'tools.refinery.java-conventions'
4}
5
6configurations {
7 mwe2 {
8 extendsFrom implementation
9 }
10}
11
12dependencies {
13 mwe2 libs.mwe2.launch
14}
15
16eclipse.classpath.plusConfigurations += [configurations.mwe2]
diff --git a/buildSrc/src/main/groovy/tools.refinery.xtend-conventions.gradle b/buildSrc/src/main/groovy/tools.refinery.xtend-conventions.gradle
new file mode 100644
index 00000000..98fc131c
--- /dev/null
+++ b/buildSrc/src/main/groovy/tools.refinery.xtend-conventions.gradle
@@ -0,0 +1,37 @@
1plugins {
2 id 'org.sonarqube'
3 id 'org.xtext.xtend'
4 id 'tools.refinery.java-conventions'
5}
6
7sourceSets {
8 main {
9 xtendOutputDir = 'src/main/xtend-gen'
10 }
11 test {
12 xtendOutputDir = 'src/test/xtend-gen'
13 }
14}
15
16xtend.generator {
17 // As of Xtext 2.26.0.M2, the Xbase compiler doesn't know how to handle Java 12 and up
18 // and the build fails with a NullPointerException if such Java version is specified.
19 javaSourceLevel = '11'
20}
21
22tasks.named('clean') {
23 delete 'src/main/xtend-gen'
24 delete 'src/test/xtend-gen'
25}
26
27sonarqube.properties {
28 properties['sonar.exclusions'] += [
29 'src/main/xtend-gen/**',
30 'src/test/xtend-gen/**',
31 ]
32}
33
34tasks.named('generateEclipseSourceFolders') {
35 dependsOn tasks.named('generateXtext')
36 dependsOn tasks.named('generateTestXtext')
37}
diff --git a/buildSrc/src/main/groovy/tools.refinery.xtext-conventions.gradle b/buildSrc/src/main/groovy/tools.refinery.xtext-conventions.gradle
new file mode 100644
index 00000000..3fd2f9d6
--- /dev/null
+++ b/buildSrc/src/main/groovy/tools.refinery.xtext-conventions.gradle
@@ -0,0 +1,21 @@
1plugins {
2 id 'org.sonarqube'
3 id 'tools.refinery.java-conventions'
4}
5
6sourceSets {
7 main {
8 java.srcDirs += ['src/main/xtext-gen']
9 resources.srcDirs += ['src/main/xtext-gen']
10 }
11}
12
13tasks.named('clean') {
14 delete 'src/main/xtext-gen'
15}
16
17sonarqube.properties {
18 properties['sonar.exclusions'] += [
19 'src/main/xtext-gen/**',
20 ]
21}