0

I have a gradle project in Eclipse with this build:

buildscript {
    repositories {
        mavenCentral()
        google()
        maven {
            url 'https://nexus.gluonhq.com/nexus/content/repositories/releases'
        }
    }
}

plugins {
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.10'
    id 'com.gluonhq.gluonfx-gradle-plugin' version '1.0.10'
    id 'org.beryx.jlink' version '2.24.4'
    id 'org.kordamp.gradle.jdeps' version '0.16.0'
//  id 'com.github.johnrengelman.shadow' version '7.1.0'
    id 'io.freefair.lombok' version '6.3.0'
    id 'eclipse'
}

repositories {
    mavenCentral()
    maven {
        url 'https://nexus.gluonhq.com/nexus/content/repositories/releases'
    }
}

mainClassName = "com.smallStuff.Main"

dependencies {
    implementation 'com.gluonhq:charm:6.1.0'

//  testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.7.2'
    testImplementation  'org.junit.jupiter:junit-jupiter-api:5.7.2'
    testImplementation  'org.hamcrest:hamcrest:2.2'
}

javafx {
    version = '17.0.2'
    modules = [ 'javafx.controls' ]
}

gluonfx {
    // target = 'ios' // Uncomment to enable iOS
    // target = 'android' // Uncomment to enable Android
    attachConfig {
        version = "4.0.13"
        services 'display', 'lifecycle', 'statusbar', 'storage'
    }
}

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(17)
    }
}

lombok {
    version = "1.18.22"
}

eclipse {
    classpath {
        downloadJavadoc = true
        downloadSources = true
        file {
            whenMerged {
                // separate output folders required to set the 'test' attribute
                entries.find { it.path == 'src/main/java' }.output = 'bin/main'
                def testSrc = entries.find { it.path == 'src/test/java' }
                testSrc.output = 'bin/test'
                testSrc.entryAttributes['test'] = 'true'

                // libraries visible for test sources only?
                entries.forEach { entry ->
                    def entryIn = { it.find { file(entry.path).equals(it) } }
                    if (entry.kind == 'lib') {
                        entry.entryAttributes['test'] =
                            entryIn(configurations.testRuntimeClasspath) &&
                            !entryIn(configurations.runtimeClasspath)
                    }
                }
            }
        }
    }
}

jlink {
    options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
    launcher {
        name = 'hellofx'
    }
}

tasks.withType(JavaExec) {
    jvmArgs += '--enable-preview'
}

tasks.withType(JavaCompile).each {
    it.options.compilerArgs.add('--enable-preview')
}

tasks.withType(JavaCompile) {
    options.compilerArgs << '-parameters'
}

wrapper {
    gradleVersion = '7.3.3'
}

where I took the code for the eclipse plugin configuration from: https://github.com/gradle/gradle/issues/4802#issuecomment-396165166

My module-info.java:

module circuits {

    requires com.gluonhq.charm.glisten;
    
    requires lombok;
}

I have my sources in src/main/java and tests in src/test/java. This is the generated classpath:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" output="bin/main" path="src/main/java">
        <attributes>
            <attribute name="gradle_scope" value="main"/>
            <attribute name="gradle_used_by_scope" value="main,test"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" output="bin/test" path="src/test/java">
        <attributes>
            <attribute name="gradle_scope" value="test"/>
            <attribute name="gradle_used_by_scope" value="test"/>
            <attribute name="test" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17/"/>
    <classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
    <classpathentry kind="output" path="bin/default"/>
</classpath>

My test class is:

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Test;

public class GateTest {

    @Test
    public void test() {
        assertEquals(1, 2);
    }

The project compiles, but when I run the JUnit test from Eclipse, I get

Error occurred during initialization of boot layer
java.lang.module.FindException: Module lombok not found, required by com.smallStuff.circuits

or Module com.gluonhq.charm.glisten not found. Not sure why sometimes it shows either. They are both declared in the module-info.java.

When I run it from gradle within Eclipse, no tests are ran and there is no error.

I also tried adding to the gradle build

plugins.withType(JavaPlugin).configureEach {
    java {
        modularity.inferModulePath = true
    }
}

which I saw here: Java 9 + maven + junit: does test code need module-info.java of its own and where to put it?

How do I run the tests?

I'm using Eclipse 4.22
Eclipse Buildship 3.1.5.v20210113-0929

Mark
  • 1,999
  • 4
  • 28
  • 62

0 Answers0