buildship
buildship copied to clipboard
Transfer the source file encoding from Gradle to Eclipse
Original post: https://bugs.eclipse.org/bugs/show_bug.cgi?id=488947
Related: gradle/gradle#898
What workaround could be applied until this is solved?
Not really at the moment, however, we'll soon implement new APIs that might be useful for you. We're going enable clients to hook into the project synchronization and to access the Tooling APIs to query arbitrary configuration from the Gradle build.
@spoenemann Our workaround is this:
eclipse {
project {
file { beforeMerged { gp ->
setEclipsePreference(file('.settings/org.eclipse.core.resources.prefs'), 'encoding/<project>', FILE_ENCODING)
}}
}
}
project.ext.setProperty = { File file, String key, String value ->
def s = file.text.replaceAll("(?ms)(^\\Q${key}\\E\\s*=).*?\$", '')
s = s.replaceAll('\n{2,}', '\n')
file.text = s + key + '=' + value + '\n'
}
project.ext.setEclipsePreference = { File prefsFile, String key, String value ->
println("edit ${prefsFile}:\t${key} := ${value}")
if (!prefsFile.exists()) {
prefsFile.parentFile.mkdirs()
prefsFile.write("eclipse.preferences.version=1\n")
}
setProperty(prefsFile, key, value)
}
FILE_ENCODING
is a property that we set in gradle.properties
in order to set compileJava.options.encoding = project.FILE_ENCODING
etc.
Unfortunately, the setting is not in effect by only a Buildship project import. It seems you need to also run the gradle eclipse task and then refresh the project in Eclipse.
Any news on this?
+1
+1
I have (sort of a) workaround. I've implemented a sample Buildship extension that reads the encoding from the Java compile options and sets it the corresponding Eclipse workspace project. It's not production-ready (no test coverage, etc.), but it should do the job. Please try it out and give me feedback. If it works fine, I might be able to merge it into the Buildship core.
Is this fix part of the next release?
The sample extension did not work for me
I'm the original reporter of this feature request in Eclipse Bugzilla back in March 2016. I still think this is a really important feature as soon as you work in a mixed-OS environment and/or you don't use a default text file encoding. This feature was present in the old Gradle-Eclipse plugin from SpringSource and it's surprising that it's not yet in Buildship, where a recurring motto is that the build script should be "the truth".
Since Eclipse 2022-06, Eclipse warns if the encoding of the project is not set. Is there a plan for support by Buildship?
Warn when a project does not have the encoding set https://bugs.eclipse.org/bugs/show_bug.cgi?id=479451
From @onmishkin
The just-released Eclipse 2022-06 (4.24) has some changes WRT project-level info about what character encoding is used for files in the project. See [this 4.24 New & Noteworthy section](https://www.eclipse.org/eclipse/news/4.24/platform.php#no-explicit-encoding-project-warning) about the change.
The projects created by Buildship apparently do not set the project's encoding info. The result is that Eclipse reports a warning like this:
Project 'xxx' has no explicit encoding set
for every imported project. There doesn't seem to be a way in Eclipse to suppress this warning. Buildship should do something to make Eclipse not warn.
Since this is a requirement now, the feature should be prioritized.
Good news :-)