diff options
Diffstat (limited to 'buildSrc/src/main/kotlin/refinery-java-conventions.gradle.kts')
-rw-r--r-- | buildSrc/src/main/kotlin/refinery-java-conventions.gradle.kts | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/buildSrc/src/main/kotlin/refinery-java-conventions.gradle.kts b/buildSrc/src/main/kotlin/refinery-java-conventions.gradle.kts new file mode 100644 index 00000000..2d5ce8b5 --- /dev/null +++ b/buildSrc/src/main/kotlin/refinery-java-conventions.gradle.kts | |||
@@ -0,0 +1,96 @@ | |||
1 | import org.gradle.accessors.dm.LibrariesForLibs | ||
2 | import org.gradle.plugins.ide.eclipse.model.EclipseModel | ||
3 | import org.gradle.plugins.ide.eclipse.model.ProjectDependency | ||
4 | import tools.refinery.buildsrc.EclipseUtils | ||
5 | |||
6 | plugins { | ||
7 | jacoco | ||
8 | java | ||
9 | } | ||
10 | |||
11 | apply(plugin = "refinery-eclipse") | ||
12 | |||
13 | repositories { | ||
14 | mavenCentral() | ||
15 | maven { | ||
16 | url = uri("https://repo.eclipse.org/content/groups/releases/") | ||
17 | } | ||
18 | } | ||
19 | |||
20 | val libs = the<LibrariesForLibs>() | ||
21 | |||
22 | dependencies { | ||
23 | compileOnly(libs.jetbrainsAnnotations) | ||
24 | testCompileOnly(libs.jetbrainsAnnotations) | ||
25 | testImplementation(libs.hamcrest) | ||
26 | testImplementation(libs.junit.api) | ||
27 | testRuntimeOnly(libs.junit.engine) | ||
28 | testImplementation(libs.junit.params) | ||
29 | testImplementation(libs.mockito.core) | ||
30 | testImplementation(libs.mockito.junit) | ||
31 | } | ||
32 | |||
33 | java.toolchain { | ||
34 | languageVersion.set(JavaLanguageVersion.of(19)) | ||
35 | } | ||
36 | |||
37 | tasks.withType(JavaCompile::class) { | ||
38 | options.release.set(17) | ||
39 | } | ||
40 | |||
41 | val test = tasks.named<Test>("test") | ||
42 | |||
43 | val jacocoTestReport = tasks.named<JacocoReport>("jacocoTestReport") | ||
44 | |||
45 | test.configure { | ||
46 | useJUnitPlatform { | ||
47 | excludeTags("slow") | ||
48 | } | ||
49 | finalizedBy(jacocoTestReport) | ||
50 | } | ||
51 | |||
52 | jacocoTestReport.configure { | ||
53 | dependsOn(test) | ||
54 | reports { | ||
55 | xml.required.set(true) | ||
56 | } | ||
57 | } | ||
58 | |||
59 | tasks.named<org.gradle.jvm.tasks.Jar>("jar") { | ||
60 | manifest { | ||
61 | attributes( | ||
62 | "Bundle-SymbolicName" to "${project.group}.${project.name}", | ||
63 | "Bundle-Version" to project.version | ||
64 | ) | ||
65 | } | ||
66 | } | ||
67 | |||
68 | val generateEclipseSourceFolders by tasks.registering | ||
69 | |||
70 | tasks.register("prepareEclipse") { | ||
71 | dependsOn(generateEclipseSourceFolders) | ||
72 | dependsOn(tasks.named("eclipseJdt")) | ||
73 | } | ||
74 | |||
75 | tasks.named("eclipseClasspath") { | ||
76 | dependsOn(generateEclipseSourceFolders) | ||
77 | } | ||
78 | |||
79 | configure<EclipseModel> { | ||
80 | EclipseUtils.patchClasspathEntries(this) { entry -> | ||
81 | if (entry.path.endsWith("-gen")) { | ||
82 | entry.entryAttributes["ignore_optional_problems"] = true | ||
83 | } | ||
84 | // If a project has a main dependency on a project and a test dependency on the testFixtures of a project, | ||
85 | // it will be erroneously added as a test-only dependency to Eclipse. As a workaround, we add all project | ||
86 | // dependencies as main dependencies (we do not deliberately use test-only project dependencies). | ||
87 | if (entry is ProjectDependency) { | ||
88 | entry.entryAttributes.remove("test") | ||
89 | } | ||
90 | } | ||
91 | |||
92 | jdt.file.withProperties { | ||
93 | // Allow @SuppressWarnings to suppress SonarLint warnings | ||
94 | this["org.eclipse.jdt.core.compiler.problem.unhandledWarningToken"] = "ignore" | ||
95 | } | ||
96 | } | ||