How do you use file to point to a resource from bu...
# community-support
b
How do you use file to point to a resource from buildSrc?
Copy code
spotbugs {
    excludeFilter = file("spotbugs/spotbugs-exclude.xml")
}
With the buildSrc layout, so when applying the reusable component it does not try to read the file from the project applied but rather from buildSrc resources
Worked, wonder if it is the best solution?
a
Is the property type of
excludeFilter
a RegularFileProperty? It'd probably be better to create a Gradle output task that would extract the file and produce to a stable output. Creating a temporary file every time will be bad for Gradle caching and up-to-date checks, since the file location will change every time.
Try this:
Copy code
val prepareSpotbugsExcludeFilter by tasks.registering {
  val file = temporaryDir.resolve("spotbugs-exclude.xml")
  outputs.file(file)
  val content = {}::class.java.getResource("/spotbugs/exclude.xml")?.readText()
  doLast {
    file.parentFile.mkdirs()
    file.writeText(content ?: error("missing /spotbugs/exclude.xml"))
  }
}

spotbugs {
  excludeFilter = prepareSpotbugsExcludeFilter.map { it.outputs.files.singleFile }
}
b
What is temporaryDir here @Adam?
b
I am getting
Copy code
Caused by: org.gradle.api.reflect.ObjectInstantiationException: Could not create an instance of type com.diffplug.gradle.spotless.SpotlessExtensionImpl.
        at         at org.gradle.internal.instantiation.generator.DependencyInjectingInstantiator.doCreate(DependencyInjectingInstantiator.java:70)
        at org.gradle.internal.instantiation.generator.DependencyInjectingInstantiator.newInstanceWithDisplayName(DependencyInjectingInstantiator.java:51)
        at org.gradle.internal.extensibility.DefaultConvention.instantiate(DefaultConvention.java:229)
        at org.gradle.internal.extensibility.DefaultConvention.create(DefaultConvention.java:150)
        at org.gradle.internal.extensibility.DefaultConvention.create(DefaultConvention.java:145)
        at com.diffplug.gradle.spotless.SpotlessPlugin.apply(SpotlessPlugin.java:53)
due to:
Copy code
Caused by: org.gradle.api.internal.AbstractMutationGuard$IllegalMutationException: Project#afterEvaluate(Action) on project ':x:x-core' cannot be executed in the current context.
        at org.gradle.api.internal.AbstractMutationGuard.createIllegalStateException(AbstractMutationGuard.java:39)
        at org.gradle.api.internal.AbstractMutationGuard.assertMutationAllowed(AbstractMutationGuard.java:34)
        at org.gradle.api.internal.project.DefaultProject.assertMutatingMethodAllowed(DefaultProject.java:1477)
        at org.gradle.api.internal.project.DefaultProject.afterEvaluate(DefaultProject.java:1054)
        at com.diffplug.gradle.spotless.SpotlessExtensionImpl.<init>(SpotlessExtensionImpl.java:42)
ideas? 😄
a
looks like a bug in the plugin implementation, so I'd raise a bug
you could try setting
enforceCheck = false
and setting up the task dependency in a more idiomatic way
b