diff --git a/build.gradle b/build.gradle index bd59092..a90e8d6 100644 --- a/build.gradle +++ b/build.gradle @@ -6,11 +6,16 @@ plugins { id "com.diffplug.spotless" version "6.25.0" } +dependencyManagement { + applyMavenExclusions = false +} + apply from: 'gradle/spotless.gradle' group = 'com.rangerforce' version = '1.0.0' def spockVersion = '2.4-M4-groovy-4.0' // Doesn't follow SimVer so using a variable +def swt_version = '3.124.100' java { sourceCompatibility = '17' @@ -40,6 +45,9 @@ dependencies { // Spock Framework testImplementation "org.spockframework:spock-core:${spockVersion}" testImplementation "org.spockframework:spock-spring:${spockVersion}" + + // Spotless workaround for Groovy + compileOnly 'org.eclipse.platform:org.eclipse.swt:3.124.100' } test { @@ -58,3 +66,25 @@ test { info.exceptionFormat = lifecycle.exceptionFormat } } + +// Setting value of osgi_platform based on OS value +def os = System.getProperty("os.name").toLowerCase() +if (os.contains("win")) { + ext.osgi_platform = "win32.win32.x86_64" +} else if (os.contains("mac")) { + ext.osgi_platform = "cocoa.macosx.x86_64" +} else if (os.contains("nix") || os.contains("nux") || os.contains("aix")) { + ext.osgi_platform = "linux" +} else { + ext.osgi_platform = "unknown" +} + +configurations.all { + resolutionStrategy { + dependencySubstitution { + // The maven property ${osgi.platform} is not handled by Gradle + // so we replace the dependency, using the osgi platform from the project settings + substitute module('org.eclipse.platform:org.eclipse.swt.${osgi.platform}') with module("org.eclipse.platform:org.eclipse.swt.${ext.osgi_platform}:${swt_version}") + } + } +} diff --git a/gradle/spotless.gradle b/gradle/spotless.gradle index a3dcba9..efe071c 100644 --- a/gradle/spotless.gradle +++ b/gradle/spotless.gradle @@ -20,4 +20,18 @@ spotless { licenseHeader '/* (C) $YEAR */' // or licenseHeaderFile } + + groovy { + target '**/*.groovy' // Specify the files to format (all .groovy files in the project) + greclipse("4.9") // Use Google Java Format for Groovy code formatting + trimTrailingWhitespace() // Trim trailing whitespace + indentWithSpaces(4) // Use 4 spaces for indentation + } + + groovyGradle { + target '**/*.gradle' // Specify the files to format (all .groovy files in the project) + greclipse("4.9") // Use Google Java Format for Groovy code formatting + trimTrailingWhitespace() // Trim trailing whitespace + indentWithSpaces(4) // Use 4 spaces for indentation + } } diff --git a/src/test/groovy/com/rangerforce/spockexample/LoadContextSpec.groovy b/src/test/groovy/com/rangerforce/spockexample/LoadContextSpec.groovy index 2c35e48..457f7ac 100644 --- a/src/test/groovy/com/rangerforce/spockexample/LoadContextSpec.groovy +++ b/src/test/groovy/com/rangerforce/spockexample/LoadContextSpec.groovy @@ -8,12 +8,11 @@ import spock.lang.Specification @SpringBootTest class LoadContextSpec extends Specification { - @Autowired (required = false) - private HelloController helloController - - def "when context is loaded then all expected beans are created"() { - expect: "the HelloController is created" - helloController - } + @Autowired (required = false) + private HelloController helloController + def "when context is loaded then all expected beans are created"() { + expect: "the HelloController is created" + helloController + } } diff --git a/src/test/groovy/com/rangerforce/spockexample/domain/repository/StarshipsRepositorySpec.groovy b/src/test/groovy/com/rangerforce/spockexample/domain/repository/StarshipsRepositorySpec.groovy index f8e8c54..b0155eb 100644 --- a/src/test/groovy/com/rangerforce/spockexample/domain/repository/StarshipsRepositorySpec.groovy +++ b/src/test/groovy/com/rangerforce/spockexample/domain/repository/StarshipsRepositorySpec.groovy @@ -1,6 +1,5 @@ package com.rangerforce.spockexample.domain.repository - import spock.lang.Shared import spock.lang.Specification diff --git a/src/test/groovy/com/rangerforce/spockexample/web/StarFleetShipResourceSpec.groovy b/src/test/groovy/com/rangerforce/spockexample/web/StarFleetShipResourceSpec.groovy index 15d65c6..59dcd83 100644 --- a/src/test/groovy/com/rangerforce/spockexample/web/StarFleetShipResourceSpec.groovy +++ b/src/test/groovy/com/rangerforce/spockexample/web/StarFleetShipResourceSpec.groovy @@ -29,9 +29,9 @@ class StarFleetShipResourceSpec extends Specification { @SpringBean private StarshipsRepository starshipsRepository = Stub() { findAll() >> [ - "USS Enterprise (NCC-1701)", - "USS Voyager (NCC-74656)", - "USS Defiant (NX-74205)" + "USS Enterprise (NCC-1701)", + "USS Voyager (NCC-74656)", + "USS Defiant (NX-74205)" ] findByRegistryName("ncc-1701") >> ussEnterprise findByRegistryName(_ as String) >> { throw new RecordNotFoundException("Not Found") }