making eclipse wtp project with gradle

2019-07-05 03:10发布

问题:

I have made wtp eclipse project with gradle. When I run 'gradle eclipse', it makes eclipse project but there is not one file '.settings/org.eclipse.core.resources.prefs'

That file has infomation for project charset

eclipse.preferences.version=1
encoding/<project>=utf-8

And here is my gradle eclipse plugin setting.

eclipse {
classpath {
    downloadSources=true
}

jdt {
    file {
        withProperties { 
            properties -> properties.setProperty("encoding//src/main/java", "utf-8")
                      properties.setProperty("encoding//src/main/resources", "utf-8")
                      properties.setProperty("encoding//src/test/java", "utf-8")
                      properties.setProperty("encoding//src/test/resources", "utf-8")
        }       
    }
}

wtp {
    component {
        contextPath = '/'
    }

    facet {
        facets = facets

        //facet name: 'jst.web', version: '2.5'
        facet name: 'jst.java', version: '6.0'
    }
}

project {
      natures 'com.google.gwt.eclipse.core.gwtNature'
      natures 'org.springframework.ide.eclipse.core.springnature'
      buildCommand 'org.springframework.ide.eclipse.core.springbuilder'
}
  }

How can I make this file?

Please help.

Thanks.

回答1:

There is a workaround mentioned (by me) on this JIRA issue

eclipseJdt << {
    File f = file('.settings/org.eclipse.core.resources.prefs')
    f.write('eclipse.preferences.version=1\n')
    f.append('encoding/<project>=utf-8')
}


回答2:

For me JB Nizet's solution didn't work as I wanted. The configuration file appeared when I explicitly invoked "eclipse" task, but I wanted it to be generated automatically after importing the project. This is what did the trick for me:

apply plugin: 'java'
apply plugin: 'eclipse'

compileJava.options.encoding = 'utf-8'

eclipse {
  jdt {
    sourceCompatibility = 1.8
    targetCompatibility = 1.8

    file {
      File dir = file('.settings')
      dir.mkdirs()

      File f = file('.settings/org.eclipse.core.resources.prefs')
      f.write('eclipse.preferences.version=1\n')
      f.append('encoding/<project>=utf-8')
    }
  }
}


cleanEclipse << {
    File f = file('.settings/org.eclipse.core.resources.prefs')
    f.delete()
}

repositories {
    jcenter()
}

dependencies {
    testCompile 'junit:junit:4.12', 'org.hamcrest:hamcrest-all:1.3'
}


标签: gradle