-
Notifications
You must be signed in to change notification settings - Fork 467
Extracting config files from resources in jars on the classpath #217
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
Comments
Yeah, ideally the tasks would be created immediately. I think we're likely to break lots of things if we change that now, though.
Everything that goes into a FormatterStep's state (e.g. config files) are loaded and parsed lazily. Usually, the first time they are loaded is when gradle is doing its up-to-date check to see if the task needs to rerun: spotless/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseFormatterStep.java Lines 69 to 71 in 995b6a9
spotless/lib/src/main/java/com/diffplug/spotless/LazyForwardingEquality.java Lines 41 to 64 in 995b6a9
spotless/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPlugin.java Lines 73 to 99 in 995b6a9
If you do I would do this: task extractConfigDeps {
// extract resources to files
}
tasks.withType(com.diffplug.gradle.spotless.SpotlessTask) {
it.dependsOn(extractConfigDependencies)
} We'd love a PR for handling resources, I think your usecase is great and we're not handling it very well at the moment. |
Hey, thanks for the detailed answer :-)
Hm, this does not seem to fit with the behavior I'm seeing. Using this sample gradle script:
I get the following stack trace which indicates the file is actually checked for existence right when I'm calling the extension in my script:
|
Oh, my bad, I did not understand that what you referred to as a "FormatterStep" was for example It does work as advertised for that 👍 |
Relevant: gradle/gradle#2760 |
I came across this page that seems very relevant |
I managed to get this working (with zips, not jars, but what's the difference really 😁). Here's an example plugins {
id 'base'
id 'maven-publish'
}
group = 'uk.co.jamiemagee'
version = '1.0'
task doZip(type: Zip) {
from ('.') {
include 'spotless/'
}
destinationDir = file(buildDir)
baseName = 'spotless-config'
}
publishing {
publications {
spotlessconfig(MavenPublication) {
artifact zipSpotlessConfig
artifactId 'spotless-config'
}
}
} Then to refer to the published zip artifact in another project's plugins {
id 'java'
id 'com.diffplug.gradle.spotless' version '3.18.0'
}
repositories {
mavenLocal()
}
configurations {
spotlessConfig
}
dependencies {
spotlessConfig 'uk.co.jamiemagee:spotless-config:+@zip'
}
spotless {
java {
eclipse().configFile resources.text.fromArchiveEntry(configurations.spotlessConfig, 'spotless/eclipseformat.xml').asFile()
}
} I hope this works for you @muryoh. @nedtwigg I'd like to write this up a bit better an put it in the docs if you think it'd be useful to more people? |
@nedtwigg If this is a feature offered, you need to ensure that the config file can be supplied lazily so it isn't unpacked during the Gradle configuration phases. If you don't make it lazy, it will significantly slow down the configuration phase of the Gradle build. |
It would be great to have this written up in the docs! I'm guessing this is a place where lazy task configuration would really shine. We have a great abandoned PR which did all of the hard parts of this (#277). But the work mentioned in this issue is helpful regardless. |
I think this is now solved well by #513. Feel free to discuss further if you think Spotless should implement something more, I'm happy to reopen. |
Hey, thanks for the plugin 👍
I like the idea, however I am unable to achieve what I would expect to be achievable.
Typically, my company uses a global import order configuration and code formatter configuration.
What we usually do is try to use opensource plugins over which we apply "standard" (as in company standard) configuration.
So typically, I would like to be able to create a plugin that applies and configures this very plugin. However, the configuration can only be done using File instances. But when you're in a JAR, you don't have a File
A possible workaround would have been to do something like
spotlessApply.doFirst {
...
}
And, there, create the files before the tasks run. However:
Do you have any pointers as to how you'd do that?
Cheers
The text was updated successfully, but these errors were encountered: