Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change XjcTask fields types to fix gradle --configuration-cache #22

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@ tasks.withType<Test>().configureEach {
}

tasks.withType<Wrapper> {
gradleVersion = "7.0"
gradleVersion = "7.3.3"
}

val compiler = javaToolchains.compilerFor {
languageVersion.set(JavaLanguageVersion.of(8))
}

tasks.withType<KotlinJvmCompile>().configureEach {
kotlinOptions.jdkHome = compiler.get().metadata.installationPath.asFile.absolutePath
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(8))
}
}

gradlePlugin {
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/github/bjornvester/xjc/XjcExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
8 changes: 7 additions & 1 deletion src/main/kotlin/com/github/bjornvester/xjc/XjcPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -37,8 +38,9 @@ class XjcPlugin : Plugin<Project> {
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")) {
Expand Down Expand Up @@ -109,6 +111,10 @@ class XjcPlugin : Plugin<Project> {
dependsOn(task)
}

project.tasks.withType(Jar::class.java).matching { it.name == "sourcesJar" }.all {
dependsOn(task)
}

return task
}

Expand Down
14 changes: 7 additions & 7 deletions src/main/kotlin/com/github/bjornvester/xjc/XjcTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -38,13 +38,13 @@ open class XjcTask @Inject constructor(
var xsdFiles = getXjcExtension().xsdFiles

@get:Classpath
val xjcConfiguration: NamedDomainObjectProvider<Configuration> = project.configurations.named(XjcPlugin.XJC_CONFIGURATION_NAME)
val xjcConfiguration: Provider<out FileCollection> = project.configurations.named(XjcPlugin.XJC_CONFIGURATION_NAME)

@get:Classpath
val xjcPluginsConfiguration: NamedDomainObjectProvider<Configuration> = project.configurations.named(XjcPlugin.XJC_PLUGINS_CONFIGURATION_NAME)
val xjcPluginsConfiguration: Provider<out FileCollection> = project.configurations.named(XjcPlugin.XJC_PLUGINS_CONFIGURATION_NAME)

@get:Classpath
val xjcBindConfiguration: NamedDomainObjectProvider<Configuration> = project.configurations.named(XjcPlugin.XJC_BIND_CONFIGURATION_NAME)
val xjcBindConfiguration: Provider<out FileCollection> = project.configurations.named(XjcPlugin.XJC_BIND_CONFIGURATION_NAME)

@Optional
@Input
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 ->
Expand Down