문제

For the sake of code style consistency I'd like to apply a set of formatting rules and save actions automatically to my Eclipse project.

I have encapsulated these rules in an EPF file using File > Export > Preferences in Eclipse.

Is there a way to import this EPF file to Eclipse using Gradle to make the rules effective? Gradle's Eclipse Plugin has the linkedResource attribute but I'm not sure if that's the way to go.

Any hints are very much appreciated.

도움이 되었습니까?

해결책

As far as I know there is no feature to import these settings automatically in Gradle. However, I could think about building something manually by providing a defaultJdtPrefs.properties file which contains all the settings for org.eclipse.jdt.core.prefs. For creating org.eclipse.jdt.ui.prefs while executing gradle eclipse you could use the following:

tasks.cleanEclipse.doLast {
    delete("${project.projectDir}/.settings/org.eclipse.jdt.ui.prefs")
}

tasks.eclipse.doLast {
    File saveActionPrefs = file("${project.projectDir}/.settings/org.eclipse.jdt.ui.prefs")
    if (saveActionPrefs.exists()) {
        logger.warn("UI preferences already exist and will not be overridden. Use task 'cleanEclipse' first.")
    } else {
        saveActionPrefs.append('''
             eclipse.preferences.version=1
             <<HERE COMES YOUR CONTENT>>
             '''. stripIndent())
    }
}

With this solution you could even the above provided EPF file containing the your preferences to create the org.eclipse.jdt.ui.prefs file using any of the Groovy build-in XML parsers ;-)

I know this is not the best solution because you have to add these things to every project (or via a custom Gradle plugin), though, the only solution I can currently think of.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top