Skip to content

Commit

Permalink
Add example scala project
Browse files Browse the repository at this point in the history
  • Loading branch information
will-molloy committed Jan 13, 2025
1 parent c806c21 commit c8309cd
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 17 deletions.
8 changes: 7 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,15 @@ allprojects {
trimTrailingWhitespace()
endWithNewline()
}
// https://github.com/diffplug/spotless/tree/main/plugin-gradle#scala
scala {
scalafmt().configFile("$rootDir/scalafmt.conf")
trimTrailingWhitespace()
endWithNewline()
}
}

// TODO Kotlin alternative?
// TODO Kotlin/Scala alternative?
apply(plugin = "checkstyle")
configure<CheckstyleExtension> {
toolVersion = "10.12.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import org.junit.jupiter.api.Test;

/**
* Integration tests for {@link HelloWorld}.
* Integration tests for {@link HelloJava}.
*
* @author <a href=https://willmolloy.com>Will Molloy</a>
*/
class HelloWorldIntegrationTest {
class HelloJavaIntegrationTest {

@Test
void test_hello() {
assertThat(new HelloWorld().hello("world")).isEqualTo("Hello world!");
assertThat(new HelloJava().hello("world")).isEqualTo("Hello world!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* @author <a href=https://willmolloy.com>Will Molloy</a>
*/
class HelloWorld {
class HelloJava {
private static final Logger log = LogManager.getLogger();

String hello(String text) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import org.junit.jupiter.api.Test;

/**
* Unit tests for {@link HelloWorld}.
* Unit tests for {@link HelloJava}.
*
* @author <a href=https://willmolloy.com>Will Molloy</a>
*/
class HelloWorldTest {
class HelloJavaTest {

@Test
void test_hello() {
assertThat(new HelloWorld().hello("world")).isEqualTo("Hello world!");
assertThat(new HelloJava().hello("world")).isEqualTo("Hello world!");
}
}
5 changes: 5 additions & 0 deletions example-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ plugins {
kotlin {
jvmToolchain(21)
}

// TODO disabling on Kotlin/Scala atm... too many false positives
spotbugs {
ignoreFailures.set(true)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ package com.willmolloy
*
* @author <a href=https://willmolloy.com>Will Molloy</a>
*/
class HelloWorld {
object HelloKotlin {

fun hello(text: String): String {
return "Hello $text!"
}
fun hello(text: String): String = "Hello $text, from Kotlin!"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package com.willmolloy
import com.google.common.truth.Truth.assertThat
import org.junit.jupiter.api.Test

/** Unit tests for [HelloWorld]. */
class HelloWorldTest {
/** Unit tests for [HelloKotlin]. */
class HelloKotlinTest {

@Test
fun `test hello`() {
assertThat(HelloWorld().hello("world")).isEqualTo("Hello world!")
assertThat(HelloKotlin.hello("world")).isEqualTo("Hello world, from Kotlin!")
}
}
12 changes: 12 additions & 0 deletions example-scala/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
plugins {
scala
}

dependencies {
implementation(libs.scala.library)
}

// TODO disabling on Kotlin/Scala atm... too many false positives
spotbugs {
ignoreFailures.set(true)
}
12 changes: 12 additions & 0 deletions example-scala/src/main/scala/com/willmolloy/HelloScala.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.willmolloy

/**
* Example main src.
*
* @author
* <a href=https://willmolloy.com>Will Molloy</a>
*/
object HelloScala {

def hello(text: String): String = s"Hello $text, from Scala!"
}
13 changes: 13 additions & 0 deletions example-scala/src/test/scala/com/willmolloy/HelloScalaTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.willmolloy

import com.google.common.truth.Truth.assertThat
import org.junit.jupiter.api.Test

/** Unit tests for [[HelloScala]]. */
class HelloScalaTest {

@Test
def test_hello(): Unit = {
assertThat(HelloScala.hello("world")).isEqualTo("Hello world, from Scala!")
}
}
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ log4j = "2.24.3"
junit = "5.11.4"
truth = "1.4.4"
mockito = "5.15.2"
# scala/kotlin
# langs
scala = "3.6.2"
kotlin = "2.1.0"

[libraries]
spotbugs-annotations = { module = "com.github.spotbugs:spotbugs-annotations", version.ref = "spotbugs" }
log4j-api = { module = "org.apache.logging.log4j:log4j-api", version.ref = "log4j" }
log4j-core = { module = "org.apache.logging.log4j:log4j-core", version.ref = "log4j" }
log4j-api = { module = "org.apache.logging.log4j:log4j-api", version.ref = "log4j" }
log4j-slf4j2 = { module = "org.apache.logging.log4j:log4j-slf4j2-impl", version.ref = "log4j" }
# test libs
junit = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit" }
Expand Down
4 changes: 4 additions & 0 deletions scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version = "3.7.3"
runner.dialect = scala3
maxColumn = 100
docstrings.style = Asterisk
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
rootProject.name = "java-template"
include("example-java")
include("example-kotlin")
include("example-scala")

0 comments on commit c8309cd

Please sign in to comment.