我用gradle制作了wtp eclipse项目。 当我运行'gradle eclipse'时,它会生成eclipse项目,但是没有一个文件'.settings / org.eclipse.core.resources.prefs'
该文件包含项目字符集的信息
eclipse.preferences.version=1
encoding/<project>=utf-8
这是我的gradle eclipse插件设置。
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'
}
}
如何制作此文件?
请帮忙。
感谢。
答案 0 :(得分:5)
eclipseJdt << {
File f = file('.settings/org.eclipse.core.resources.prefs')
f.write('eclipse.preferences.version=1\n')
f.append('encoding/<project>=utf-8')
}
答案 1 :(得分:1)
对我来说,JB Nizet的解决方案并不像我想的那样有效。当我明确调用“eclipse”任务时出现配置文件,但我希望它在导入项目后自动生成。这就是我的诀窍:
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'
}