diff --git a/build.gradle.kts b/build.gradle.kts index 3b4aa7d..0b454b5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -30,15 +30,13 @@ tasks.withType().configureEach { } tasks.withType { - gradleVersion = "7.0" + gradleVersion = "7.3.3" } -val compiler = javaToolchains.compilerFor { - languageVersion.set(JavaLanguageVersion.of(8)) -} - -tasks.withType().configureEach { - kotlinOptions.jdkHome = compiler.get().metadata.installationPath.asFile.absolutePath +java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(8)) + } } gradlePlugin { diff --git a/src/main/kotlin/com/github/bjornvester/xjc/XjcExtension.kt b/src/main/kotlin/com/github/bjornvester/xjc/XjcExtension.kt index 5f87380..b437366 100644 --- a/src/main/kotlin/com/github/bjornvester/xjc/XjcExtension.kt +++ b/src/main/kotlin/com/github/bjornvester/xjc/XjcExtension.kt @@ -7,7 +7,7 @@ import org.gradle.api.model.ObjectFactory import javax.inject.Inject open class XjcExtension @Inject constructor(objects: ObjectFactory, layout: ProjectLayout) : XjcExtensionGroup { - val xjcVersion = objects.property(String::class.java).convention("2.3.3") + val xjcVersion = objects.property(String::class.java).value("2.3.3") override val name = "Defaults" override val xsdDir = objects.directoryProperty().convention(layout.projectDirectory.dir("src/main/resources")) diff --git a/src/main/kotlin/com/github/bjornvester/xjc/XjcPlugin.kt b/src/main/kotlin/com/github/bjornvester/xjc/XjcPlugin.kt index fc856fe..7a7c971 100644 --- a/src/main/kotlin/com/github/bjornvester/xjc/XjcPlugin.kt +++ b/src/main/kotlin/com/github/bjornvester/xjc/XjcPlugin.kt @@ -9,6 +9,7 @@ import org.gradle.api.plugins.JavaPlugin import org.gradle.api.tasks.SourceSet.MAIN_SOURCE_SET_NAME import org.gradle.api.tasks.SourceSetContainer import org.gradle.api.tasks.TaskProvider +import org.gradle.api.tasks.bundling.Jar import org.gradle.util.GradleVersion import java.io.Serializable @@ -37,8 +38,9 @@ class XjcPlugin : Plugin { createConfiguration(project, XJC_BIND_CONFIGURATION_NAME) createConfiguration(project, XJC_PLUGINS_CONFIGURATION_NAME) - xjcConfiguration.defaultDependencies { + xjcConfiguration.withDependencies { addLater(extension.xjcVersion.map { project.dependencies.create("org.glassfish.jaxb:jaxb-xjc:$it") }) + addLater(extension.xjcVersion.map { project.dependencies.create("org.glassfish.jaxb:jaxb-runtime:$it") }) } if (GradleVersion.current() <= GradleVersion.version("6.8")) { @@ -109,6 +111,10 @@ class XjcPlugin : Plugin { dependsOn(task) } + project.tasks.withType(Jar::class.java).matching { it.name == "sourcesJar" }.all { + dependsOn(task) + } + return task } diff --git a/src/main/kotlin/com/github/bjornvester/xjc/XjcTask.kt b/src/main/kotlin/com/github/bjornvester/xjc/XjcTask.kt index bbe5e75..9e54586 100644 --- a/src/main/kotlin/com/github/bjornvester/xjc/XjcTask.kt +++ b/src/main/kotlin/com/github/bjornvester/xjc/XjcTask.kt @@ -3,15 +3,15 @@ package com.github.bjornvester.xjc import com.github.bjornvester.xjc.XjcPlugin.Companion.XJC_EXTENSION_NAME import org.gradle.api.DefaultTask import org.gradle.api.GradleException -import org.gradle.api.NamedDomainObjectProvider -import org.gradle.api.artifacts.Configuration import org.gradle.api.file.DirectoryProperty +import org.gradle.api.file.FileCollection import org.gradle.api.file.FileSystemOperations import org.gradle.api.file.ProjectLayout import org.gradle.api.model.ObjectFactory import org.gradle.api.plugins.BasePlugin import org.gradle.api.provider.ListProperty import org.gradle.api.provider.Property +import org.gradle.api.provider.Provider import org.gradle.api.tasks.* import org.gradle.workers.WorkerExecutor import javax.inject.Inject @@ -38,13 +38,13 @@ open class XjcTask @Inject constructor( var xsdFiles = getXjcExtension().xsdFiles @get:Classpath - val xjcConfiguration: NamedDomainObjectProvider = project.configurations.named(XjcPlugin.XJC_CONFIGURATION_NAME) + val xjcConfiguration: Provider = project.configurations.named(XjcPlugin.XJC_CONFIGURATION_NAME) @get:Classpath - val xjcPluginsConfiguration: NamedDomainObjectProvider = project.configurations.named(XjcPlugin.XJC_PLUGINS_CONFIGURATION_NAME) + val xjcPluginsConfiguration: Provider = project.configurations.named(XjcPlugin.XJC_PLUGINS_CONFIGURATION_NAME) @get:Classpath - val xjcBindConfiguration: NamedDomainObjectProvider = project.configurations.named(XjcPlugin.XJC_BIND_CONFIGURATION_NAME) + val xjcBindConfiguration: Provider = project.configurations.named(XjcPlugin.XJC_BIND_CONFIGURATION_NAME) @Optional @Input @@ -88,7 +88,7 @@ open class XjcTask @Inject constructor( logger.info("Loading XSD files ${xsdFiles.files}") logger.debug("XSD files are loaded from ${xsdDir.get()}") - val xjcClasspath = xjcConfiguration.get().resolve() + xjcPluginsConfiguration + val xjcClasspath = xjcConfiguration.get().files + xjcPluginsConfiguration.get().files logger.debug("Loading JAR files for XJC: $xjcClasspath") extractBindFilesFromJars() @@ -171,7 +171,7 @@ open class XjcTask @Inject constructor( * that causes the jar files to be locked on Windows. To avoid this, we extract the bind files ourselves. */ private fun extractBindFilesFromJars() { - val bindJarFiles = xjcBindConfiguration.get().resolve() + val bindJarFiles = xjcBindConfiguration.get().files logger.debug("Loading binding JAR files: $bindJarFiles") bindJarFiles.forEach { bindJarFile ->