Skip to content

Commit 4be00b7

Browse files
committed
WIP - try out gradle init
1 parent 8f5f244 commit 4be00b7

30 files changed

+451
-203
lines changed

.gitattributes

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# https://help.github.com/articles/dealing-with-line-endings/
3+
#
4+
# Linux start script should use lf
5+
/gradlew text eol=lf
6+
7+
# These are Windows script files and should use crlf
8+
*.bat text eol=crlf
9+
10+
# Binary files should be left untouched
11+
*.jar binary
12+

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,8 @@ gradle-app.setting
2828
# Demo data sets
2929
yelp_json
3030
yelp_graph
31+
32+
# Ignore Gradle build output directory
33+
build
34+
35+
gradle.properties

build.gradle

Lines changed: 76 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
plugins {
2-
id 'java-library'
3-
id 'scala'
4-
id 'com.github.hierynomus.license' version '0.16.3-63da64d' apply false
5-
id 'com.gradleup.shadow' version '9.2.2' apply false
6-
id 'com.github.alisiikh.scalastyle' version '3.5.0' apply false
7-
id 'me.champeau.jmh' version '0.7.3' apply false
8-
id "ch.kk7.spawn" version "1.0.20180924200750" apply false
2+
id 'buildlogic.scala-application-conventions'
3+
4+
alias(libs.plugins.champeau.jmh).apply(false)
5+
alias(libs.plugins.licencs).apply(false)
6+
alias(libs.plugins.scalastyle).apply(false)
7+
alias(libs.plugins.shadowjar).apply(false)
8+
alias(libs.plugins.spawn).apply(false)
99
}
1010

1111
apply from: 'build.params.gradle'
1212
apply plugin: 'base'
1313

14+
configurations {
15+
resolvableRuntimeClasspath {
16+
extendsFrom configurations.runtimeClasspath
17+
canBeResolved = true
18+
canBeConsumed = false
19+
description = 'Resolvable runtime classpath configuration.'
20+
}
21+
}
22+
23+
1424
allprojects {
1525
java {
16-
sourceCompatibility = ver.jvm
17-
targetCompatibility = ver.jvm
26+
sourceCompatibility = 21
27+
targetCompatibility = 21
1828
}
1929

2030
scala {
@@ -37,21 +47,21 @@ subprojects {
3747
}
3848

3949
dependencies {
40-
implementation group: 'org.scala-lang', name: 'scala-library', version: ver.scala.full
50+
implementation libs.scala.library
4151

4252
// Seems we need to lock these down, otherwise we get runtime errors on reflection
43-
implementation group: 'org.scala-lang', name: 'scala-reflect', version: ver.scala.full
44-
implementation group: 'org.scala-lang', name: 'scala-compiler', version: ver.scala.full
45-
46-
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: ver.log4j.main
47-
implementation group: 'org.apache.logging.log4j', name: "log4j-api-scala".scala(), version: ver.log4j.scala
48-
49-
testImplementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: ver.log4j.main
50-
testImplementation group: 'org.scalatest', name: "scalatest".scala(), version: ver.scalatest
51-
testImplementation group: 'org.scalacheck', name: "scalacheck".scala(), version: ver.scalacheck
52-
testImplementation group: 'junit', name: 'junit', version: ver.junit.main
53-
testImplementation group: 'org.mockito', name: 'mockito-all', version: ver.mockito
54-
testRuntimeOnly group: 'org.junit.platform', name: 'junit-platform-runner', version: ver.junit.runner
53+
implementation libs.scala.compiler
54+
implementation libs.scala.reflect
55+
56+
implementation libs.log4j.api
57+
implementation libs.log4j.api.scala
58+
59+
testImplementation libs.log4j.core
60+
testImplementation libs.scalatest
61+
testImplementation libs.scalacheck
62+
testImplementation libs.junit
63+
testImplementation libs.mockito
64+
testRuntimeOnly libs.junit.runner
5565
}
5666

5767
test {
@@ -68,47 +78,72 @@ subprojects {
6878
'-Ywarn-adapted-args'
6979
]
7080

71-
tasks.withType(ScalaCompile) {
81+
tasks.withType(Test).configureEach {
82+
// JVM args required by spark (see org.apache.spark.launcher.JavaModuleOptions)
83+
jvmArgs(
84+
'-XX:+IgnoreUnrecognizedVMOptions',
85+
'--add-exports=java.base/sun.nio.ch=ALL-UNNAMED',
86+
'--add-opens=java.base/java.lang.invoke=ALL-UNNAMED',
87+
'--add-opens=java.base/java.lang=ALL-UNNAMED',
88+
'--add-opens=java.base/java.lang.invoke=ALL-UNNAMED',
89+
'--add-opens=java.base/java.lang.reflect=ALL-UNNAMED',
90+
'--add-opens=java.base/java.io=ALL-UNNAMED',
91+
'--add-opens=java.base/java.net=ALL-UNNAMED',
92+
'--add-opens=java.base/java.nio=ALL-UNNAMED',
93+
'--add-opens=java.base/java.util=ALL-UNNAMED',
94+
'--add-opens=java.base/java.util.concurrent=ALL-UNNAMED',
95+
'--add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED',
96+
'--add-opens=java.base/jdk.internal.ref=ALL-UNNAMED',
97+
'--add-opens=java.base/sun.nio.ch=ALL-UNNAMED',
98+
'--add-opens=java.base/sun.nio.cs=ALL-UNNAMED',
99+
'--add-opens=java.base/sun.security.action=ALL-UNNAMED',
100+
'--add-opens=java.base/sun.util.calendar=ALL-UNNAMED',
101+
'--add-opens=java.security.jgss/sun.security.krb5=ALL-UNNAMED',
102+
'-Djdk.reflect.useDirectMethodHandle=false'
103+
)
104+
}
105+
106+
tasks.withType(ScalaCompile).configureEach {
72107
options.encoding = 'UTF-8'
73108
scalaCompileOptions.additionalParameters = scalacParameters
74109
}
75110

76-
tasks.withType(ScalaDoc) {
111+
tasks.withType(ScalaDoc).configureEach {
77112
scalaDocOptions.additionalParameters = scalacParameters
78113
}
79114

80-
task sourceJar(type: Jar) {
115+
tasks.register('sourceJar', Jar) {
81116
archiveClassifier = 'sources'
82117
from(sourceSets.main.allSource)
83118
}
84119

85-
task docJar(type: Jar) {
120+
tasks.register('docJar', Jar) {
86121
dependsOn tasks.scaladoc
87122
archiveClassifier = 'javadoc'
88123
from(tasks.scaladoc.destinationDir)
89124
}
90125

91-
task testJar(type: Jar) {
126+
tasks.register('testJar', Jar) {
92127
archiveClassifier = 'tests'
93128
from(sourceSets.test.output)
94129
}
95130

96-
tasks.withType(Jar) {
131+
tasks.withType(Jar).configureEach {
97132
from(tasks.generateLicensesFiles) {
98133
into("META-INF/")
99134
}
100135
}
101136

102-
task licenseFile {
137+
tasks.register('licenseFile') {
103138
outputs.file(project.parent.file('LICENSE.txt'))
104139
}
105140

106-
task dependencySearch(type: DependencyInsightReportTask) {
141+
tasks.register('dependencySearch', DependencyInsightReportTask) {
107142
description = 'Searches all projects for a dependency'
108143
group = 'help'
109144
}
110145

111-
task runApp {
146+
tasks.register('runApp') {
112147
dependsOn tasks.classes
113148
group = 'run'
114149
description = 'Run a custom Scala app (use -PmainClass=com.my.package.App)'
@@ -120,12 +155,20 @@ subprojects {
120155
}
121156
}
122157

158+
configurations {
159+
resolvableDefault {
160+
extendsFrom configurations.default
161+
canBeResolved = true
162+
canBeConsumed = false
163+
description = 'Resolvable default configuration.'
164+
}
165+
}
123166
// copied from https://stackoverflow.com/a/38058671/568723
124-
task depSize {
167+
tasks.register('depSize') {
125168
description = 'Lists all dependencies sorted by their size'
126169
doLast {
127170
final formatStr = "%,10.2f"
128-
final conf = configurations.default
171+
final conf = configurations.resolvableDefault
129172
final size = conf.collect { it.length() / (1024 * 1024) }.sum()
130173
final out = new StringBuffer()
131174
out << 'Total dependencies size:'.padRight(45)

build.licenses.gradle

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ subprojects { proj ->
6666
}
6767
tasks.check.dependsOn tasks.license
6868

69+
// Define a resolvable configuration for license reporting
70+
configurations {
71+
licenseReportRuntimeClasspath {
72+
extendsFrom configurations.runtimeClasspath
73+
canBeResolved = true
74+
canBeConsumed = false
75+
description = 'Resolvable configuration for license reporting.'
76+
}
77+
}
78+
6979
// Dependency license reporting
7080
downloadLicenses {
7181
report {
@@ -76,7 +86,7 @@ subprojects { proj ->
7686
html.enabled = false
7787
html.destination = file(getLayout().getBuildDirectory().dir('reports/license'))
7888
}
79-
dependencyConfiguration = 'runtimeClasspath'
89+
dependencyConfiguration = 'resolvableRuntimeClasspath'
8090
aliases = allowList.collectEntries { lic ->
8191
def actual = license(lic.name, lic.url)
8292
def alternatives = lic.aliases.collect { it.url ? license(it.name, it.url) : it.name }

build.params.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ ext {
77
ver = [
88
self : '0.4.3-SNAPSHOT',
99

10-
jvm : '21',
11-
1210
scala : [major: '2.12',
1311
full : '2.12.20'],
1412

buildSrc/build.gradle

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* This file was generated by the Gradle 'init' task.
3+
*/
4+
5+
plugins {
6+
// Support convention plugins written in Groovy. Convention plugins are build scripts in 'src/main' that automatically become available as plugins in the main build.
7+
id 'groovy-gradle-plugin'
8+
}
9+
10+
repositories {
11+
// Use the plugin portal to apply community plugins in convention plugins.
12+
gradlePluginPortal()
13+
}

buildSrc/settings.gradle

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* This file was generated by the Gradle 'init' task.
3+
*
4+
* This settings file is used to specify which projects to include in your build-logic build.
5+
*/
6+
7+
dependencyResolutionManagement {
8+
// Reuse version catalog from the main build.
9+
versionCatalogs {
10+
create('libs', { from(files("../gradle/libs.versions.toml")) })
11+
}
12+
}
13+
14+
rootProject.name = 'buildSrc'
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* This file was generated by the Gradle 'init' task.
3+
*/
4+
5+
plugins {
6+
// Apply the common convention plugin for shared build configuration between library and application projects.
7+
id 'buildlogic.scala-common-conventions'
8+
9+
id 'application'
10+
// Apply the application plugin to add support for building a CLI application in Java.
11+
id 'base'
12+
13+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* This file was generated by the Gradle 'init' task.
3+
*/
4+
5+
plugins {
6+
// Apply the scala Plugin to add support for Scala.
7+
id 'scala'
8+
}
9+
10+
repositories {
11+
// Use Maven Central for resolving dependencies.
12+
mavenCentral()
13+
mavenLocal()
14+
}
15+
//
16+
//dependencies {
17+
// constraints {
18+
// // Define dependency versions as constraints
19+
// implementation 'org.apache.commons:commons-text:1.13.0'
20+
//
21+
// implementation libs.scala.library
22+
// }
23+
//
24+
// implementation 'org.scala-lang:scala-library'
25+
//
26+
// // Use JUnit Jupiter for testing.
27+
// testImplementation 'org.junit.jupiter:junit-jupiter:5.12.1'
28+
//
29+
// testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
30+
//}
31+
32+
// Apply a specific Java toolchain to ease working on different environments.
33+
java {
34+
toolchain {
35+
languageVersion = JavaLanguageVersion.of(21)
36+
}
37+
}
38+
39+
tasks.named('test') {
40+
// Use JUnit Platform for unit tests.
41+
useJUnitPlatform()
42+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* This file was generated by the Gradle 'init' task.
3+
*/
4+
5+
plugins {
6+
// Apply the common convention plugin for shared build configuration between library and application projects.
7+
id 'buildlogic.scala-common-conventions'
8+
9+
// Apply the java-library plugin for API and implementation separation.
10+
id 'java-library'
11+
}

0 commit comments

Comments
 (0)