IntershopCommunicationsAG / jaxb-gradle-plugin

Gradle JAXB code generation plugin
Apache License 2.0
33 stars 15 forks source link

Genereated classes can not be resolved #35

Open helmbold opened 4 years ago

helmbold commented 4 years ago

If I generate Java classes from xsd files the resulting classes are not found. During compilation I get Unresolved reference: MyClass errors.

The configuration is like the following:

plugins {
    kotlin("jvm") version "1.3.72"
    kotlin("plugin.spring") version "1.3.72"
    id("com.intershop.gradle.jaxb") version "4.3.0"
}

jaxb {
    javaGen {
        create("example1") {
            language = "XMLSCHEMA"
            schemas = layout.files(
                "src/main/generation/example1a.xsd",
                "src/main/generation/example1b.xsd"
            )
            bindings = layout.files("src/main/generation/example1.xjb")
        }
        create("example2") {
            language = "XMLSCHEMA"
            schemas = layout.files("src/main/generation/example2.xsd")
            bindings = layout.files("src/main/generation/example2.xjb")
        }
    }
}

sourceSets {
    main {
        java {
            srcDirs += file("generated/jaxb/java")
        }
    }
}

All class files are generated as expected. They are located under "build/generated/jaxb/java".

Following the documentation they should be added to the source set "main" automatically, but even adding them explicitly with the sourceSets block doesn't help.

Everything was working with the plug-in version 4.0.0.

mschorsch commented 9 months ago

The problem is that the plugin does not support Kotlin properly. The generated source files are only added to the Java sourceset "main" and not to the Kotlin sourceset "main". In addition, the generation of the classes should be done before the task "compileKotlin".

Something like this:

plugins {
    id("com.intershop.gradle.jaxb") version "6.0.0"
}

jaxb {
     // generate java code from schema
     javaGen {
        //generates a 'project' schema file from existing java code
        register("name") {
            schema = file("schema.xsd")
            binding = file("binding.xjb")
        }
    }
}

sourceSets {
    main {
        kotlin {
            srcDir("${project.buildDir}/generated/jaxb/java/name")
        }
    }
}

tasks.compileKotlin {
   dependsOn("jaxbJavaGenName")
}