How do I configure KoTest with Gradle in a LibGdx project? Currently can't build because StringSpec is not recognised - gradle

I have a standard LibGdx project setup by the LibGdx tool, only targeting desktop. It uses Gradle (Groovy DSL) to manage dependencies and tasks. I've converted the core module to Kotlin, and I'm trying to add a Kotlin test module using Kotest.
I've followed the Kotest instructions for Gradle on their GitHub but the compile is failing because StringSpec isn't reocgnised (Unresolved reference: StringSpec). I think LibGdx's default Gradle setup may be a little outdated or use older syntax/structure, and perhaps it's conflicting with Kotest's instructions intended for newer versions of Gradle?
For now I've removed any test and am just trying to get it to recognise StringSpec and compile. I've not even reached the stage of getting IntelliJ to recognise and run the tests. Here's what I have so far:
core.tests/tests/com/me/game/AcceptanceTests.kt
package com.jansky.myproject
class AcceptanceTests : StringSpec() {
}
core.tests/gradle.build
version '1.0'
sourceCompatibility = 1.7
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
sourceSets.main.java.srcDirs = [ "tests/" ]
tasks.withType(Test) {
useJUnitPlatform()
}
eclipse.project.name = appName + "-core.tests"
./build.gradle (ie the root buildfile)
buildscript {
ext.kotlinVersion = '1.3.71'
repositories {
mavenLocal()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
jcenter()
google()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
allprojects {
apply plugin: "eclipse"
version = '1.0'
ext {
appName = "game"
gdxVersion = '1.9.10'
roboVMVersion = '2.3.8'
box2DLightsVersion = '1.4'
ashleyVersion = '1.7.0'
aiVersion = '1.8.0'
}
repositories {
mavenLocal()
mavenCentral()
jcenter()
google()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
}
project(":desktop") {
apply plugin: "kotlin"
dependencies {
implementation project(":core")
api "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.ashley:ashley:1.7.3"
compile group: 'io.github.libktx', name: 'ktx-ashley', version: '1.9.10-b4'
}
}
project(":core") {
apply plugin: "kotlin"
dependencies {
api "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
compile "com.badlogicgames.ashley:ashley:1.7.3"
compile group: 'io.github.libktx', name: 'ktx-ashley', version: '1.9.10-b4'
}
}
project(":core.tests") {
apply plugin: "kotlin"
test {
useJUnitPlatform()
}
dependencies {
api "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
compile "com.badlogicgames.ashley:ashley:1.7.3"
compile group: 'io.github.libktx', name: 'ktx-ashley', version: '1.9.10-b4'
implementation 'io.kotest:kotest-runner-junit5:4.0.2'
implementation 'io.kotest:kotest-assertions-core:4.0.2'
}
}
settings.gradle
include 'desktop', 'core', 'core.tests'
Gradle-wrapper.properties
#Sat Apr 04 15:53:20 BST 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
I don't have much JVM experience, so I'm at a bit of a loss. Hopefully I've missed something that's obvious to someone that knows Gradle better. Any ideas?

Related

Gradle generateGrammarSource task isn't working

I want to generate antlr4 lexer using gradle generateGrammarSource task.
Path to g4 file is src/main/antlr4/my/package/mygrammar.g4
I tried to use some examples I found so build.gradle has the following code:
buildscript {
ext.kotlin_version = '1.3.20'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
group 'my.package'
version '1.0-SNAPSHOT'
apply plugin: 'kotlin'
apply plugin: 'antlr'
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
compile group: 'org.antlr', name: 'antlr4', version: '4.7.2'
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
}
generateGrammarSource {
arguments += ['-package', 'my.package']
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
Executing generateGrammarSource task generates nothing and gives the following output:
:generateGrammarSource NO-SOURCE
BUILD SUCCESSFUL in 0s
How can I fix it?
you need to create directory src/main/antlr and add Kotlin grammar files into there. most likely the my/package/ is the reason why it cannot find the grammar files; while this answers hints for, to add generated sources to the source-set. see The ANTLR Plugin.

Gradle Kotlin Native - You have not specified any compilation arguments. No output has been produced

I'm pretty new to Gradle and Kotlin Native. I want to setup my build.gradle so that I can use Native to compile my code. I'm using the Konan plugin to do this. It worked fine when I hard-coded my class in the konanArtifacts.program.srcFiles. But obviously if I add more classes, I'll have to add the paths to srcFiles and I don't (and shouldn't) need to. So I looked around to find a way to add any classes I add automatically, and I attempted sourceSets. But when I try to run the compileKonanClientMingw task now my gradle console gives me the following:
error: you have not specified any compilation arguments. No output has been produced.
I'm not entirely sure that I'm using sourceSets correctly, but this seems to be the farthest I got. Below is my build.gradle
build.gradle:
buildscript {
ext.kotlin_version = '1.2.41'
ext.konan_version = '0.6'
repositories {
mavenCentral()
maven {
url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies"
}
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:$konan_version"
}
}
plugins {
id 'java'
}
group 'net.dev909'
version '1.0'
apply plugin: 'kotlin'
apply plugin: 'konan'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
testCompile group: 'junit', name: 'junit', version: '4.12'
}
sourceSets.main.allSource.srcDir '/src/main/kotlin/'
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
konanArtifacts {
program('client-' + version) {
srcFiles sourceSets.main.runtimeClasspath
}
}
Source sets are a part of the Java world and the Java plugin, so the Kotlin/Native plugin avoids using them to be independent on Java. But you still able to compile a bunch of classes, just specify the srcDir parameter:
konanArtifacts {
program('client-' + version) {
srcDir 'src/main/kotlin/'
}
}
Also note that src/main/kotlin/ is a default source path. So if you use only this path, you don't need to specify it explicitly. You may just write:
konanArtifacts {
program('client-' + version)
}

One Gradle Thymeleaf project reloads on resource change, the other relaunches

EDIT: I've narrowed down the behavior a bit, not sure if there's a way to accomplish what I need.
Turns out, my app has the Thymeleaf templates one level down in the source tree:
src/main/resources/tools-server/templates
And I set this in my tools-server.yml file that gets explicitly loaded at application launch. Removing that specification from my configuration, and moving the templates directory up one level to
src/main/resources/templates
Allows spring-boot-devtools to simply reload the template without restarting the app. I think I’ll file a bug with the project, unless there’s a way around it.
I'm still getting the hang of Spring Boot, so bear with me. I've created two projects over the last few months, each starting from different examples found online.
With respect to reloading Thymeleaf templates, the first project does it neatly when they change, issuing two log messages when a template changes, and nothing more. The other does a complete stop and restart of the application, which causes problems because it re-creates the temporary security password, among other things (it also takes longer).
The two gradle.build files are nearly identical, with slightly different dependencies. I'm not sure if those are the differences causing the different behavior.
The working one:
buildscript
{
ext
{
springBootVersion = "1.4.3.RELEASE"
}
repositories
{
mavenCentral()
}
dependencies
{
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath group: "com.layer", name: "gradle-git-repo-plugin", version: "2.0.2"
}
}
apply plugin: "git-repo"
apply plugin: "java"
apply plugin: "maven"
apply plugin: "spring-boot"
jar
{
baseName = "HOA"
version = "0.0.1-SNAPSHOT"
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories
{
mavenCentral()
maven { url "https://maven.atlassian.com/3rdparty/" }
maven { url "https://mvnrepository.com/artifact/" }
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
}
dependencies
{
compile group: "org.mindrot", name: "jbcrypt", version: "0.4-atlassian-1"
compile group: "org.eclipse.persistence", name: "javax.persistence", version: "2.1.1"
compile group: "org.springframework.data", name: "spring-data-jpa", version: "1.10.4.RELEASE"
compile group: "org.springframework.hateoas", name: "spring-hateoas", version: "0.21.0.RELEASE"
compile group: "com.h2database", name: "h2", version: "1.4.192"
compile("org.springframework.boot:spring-boot-devtools")
compile("org.springframework.boot:spring-boot-starter-aop")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.boot:spring-boot-starter-groovy-templates")
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-starter-web")
// Automated Testing
testCompile("org.springframework.boot:spring-boot-starter-test")
testCompile("org.springframework.restdocs:spring-restdocs-mockmvc")
}
dependencyManagement
{
imports
{
mavenBom "org.springframework.cloud:spring-cloud-dependencies:Camden.SR1"
}
}
compileJava
{
options.compilerArgs << "-Xlint:all" << "-Xdiags:verbose"
}
bootRepackage
{
mainClass = "com.latencyzero.hoa.Application"
}
bootRun
{
addResources = true
}
The messy one:
buildscript
{
ext
{
springBootVersion = '1.4.3.RELEASE'
}
repositories
{
mavenCentral()
}
dependencies
{
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'org.springframework.boot'
sourceCompatibility = 1.8
targetCompatibility = 1.8
archivesBaseName = 'toolcrib'
compileJava
{
options.compilerArgs << "-Xlint:all" << "-Xdiags:verbose"
}
jar
{
manifest
{
attributes 'Implementation-Title': 'ToolCrib',
'Implementation-Version': version
}
}
repositories
{
mavenCentral()
}
dependencyManagement
{
imports
{
mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Camden.SR3'
}
}
dependencies
{
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.0'
compile('org.springframework.boot:spring-boot-devtools')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
runtime('org.postgresql:postgresql')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
springBoot
{
mainClass = "com.latencyzero.toolcrib.services.tools.ToolsServer"
}
bootRun
{
addResources = true
}
Thanks for any insight!
Have you had a look to the documentation
By default changing resources in /META-INF/maven, /META-INF/resources, /resources, /static, /public or /templates will not trigger a restart but will trigger a live reload.
And
If you want to customize these exclusions you can use the spring.devtools.restart.exclude
There is also spring.devtools.restart.additional-exclude to add more excludes and keep the defaults. In your case, you should add the following to your configuration:
spring.devtools.restart.additional-exclude=classpath:/tools-server/templates/

Gradle changing module from nexus snapshot repo not updated

I have a problem with a snapshot artifact not being uploaded.
I'm using snapshot version. Atrifact is marked explicitly as changing: true and cacheChangingModulesFor is set to 0 seconds.
When i run --refresh-dependecies the artifact is redownloaded properly.
I found the problem while using gradle 2.9. But after upgrading to 2.14.1 the issue remains.
Below is my build.gradle file:
buildscript {
ext {
springBootVersion = '1.3.5.RELEASE'
}
repositories {
mavenCentral()
maven { url 'http://repo.spring.io/plugins-release' }
}
// dependencies for plugins
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
classpath 'org.springframework.build.gradle:propdeps-plugin:0.0.7'
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'
apply plugin: 'propdeps'
apply plugin: 'propdeps-maven'
apply plugin: 'propdeps-idea'
configurations.all {
// Check for updates every build
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
jar {
baseName = 'someproject'
version = '0.0.1-SNAPSHOT'
}
war {
baseName = "someproject"
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://jitpack.io" }
maven {
url 'http://nexus.example.com:8081/nexus/content/repositories/java-libs-snapshots/'
credentials {
username "someuser"
password "somepassword"
}
}
}
// enables to run with dev profile: $ gradle local bootRun
task local << {
bootRun.systemProperty 'spring.profiles.active', 'local'
}
bootRun {
jvmArgs = ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"]
}
dependencies {
compile 'mysql:mysql-connector-java'
compile 'org.springframework.boot:spring-boot-starter-web'
compile group: "pl.example", name: "name", version: "0.7.6.1-SNAPSHOT", changing: true
compile 'org.jadira.usertype:usertype.core:5.0.0.GA'
compile group: 'com.rometools', name: 'rome', version: '1.6.0'
compile group: 'org.jsoup', name: 'jsoup', version: '1.9.2'
compile 'org.hibernate:hibernate-search:5.5.3.Final'
compile 'org.projectlombok:lombok:1.16.6'
}
I think you maybe have the syntax for the changing dependency slightly wrong.
Can you try replacing:
compile group: "pl.example", name: "name", version: "0.7.6.1-SNAPSHOT", changing: true
with:
compile ("pl.example:name:0.7.6.1-SNAPSHOT"){ changing = true }
Can you also try adding a line to the resolutionStrategy for cacheDynamicVersionsFor as follows:
configurations.all {
resolutionStrategy {
cacheDynamicVersionsFor 0, "seconds"
cacheChangingModulesFor 0, "seconds"
}
}

Gradle unable to find existing m2 library

Can anyone tell me why gradle fails to load j2v8 dependency with the following script :
apply plugin: 'java'
sourceCompatibility = 1.7
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
test {
useTestNG()
include '**'
testLogging.showStandardStreams = true
}
repositories {
mavenCentral()
}
dependencies {
compile "com.google.guava:guava:18.0"
compile "com.google.code.findbugs:jsr305:3.0.0"
compile 'com.eclipsesource.j2v8:j2v8_linux_x86_64:3.1.6'
testCompile "org.testng:testng:6.9.9"
}
using 'com.eclipsesource.j2v8:j2v8_linux_x86_64:3.1.1' works well but with 3.1.6 I get the error Error:(18, 13) Failed to resolve: com.eclipsesource.j2v8:j2v8_linux_x86_64:3.1.6
To use local maven's m2 cache:
repositories {
mavenLocal()
}

Resources