2017-03-24 128 views
1

我是IntelliJ和Gradle的新手,但我对Java和Eclipse有足够的经验。我从wsdl文件生成了一些java类。我把它们放在src/main/resources的文件夹名称 - “generatedsources”下。如何从Intellij上的Gradle的checkstyle中排除文件夹

我尝试使用IntelliJ上的gradle来阻止此文件夹及其子文件夹(如src/main/resources/generatedsources/*)的checkstyle。

我试过一些这样的行;

task checkstyle(type: Checkstyle) { 
     source 'src' 
    // include '**/*.java' 
    // exclude '**/gen/**' 
    // exclude '**/R.java' 
    // exclude '**/BuildConfig.java' 
     exclude 'src/main/resources/generatedsources/**' 
    } 

但我又失败了。

build.gradle;在tasks.withType

apply plugin: 'war' 
apply plugin: 'jetty' 
apply plugin: 'checkstyle' 
apply plugin: 'java' 
apply plugin: 'no.nils.wsdl2java' 

sourceCompatibility = 1.7 
version = '1.0' 

description = """BLABLABLA_application""" 

war.archiveName = "BLABLABLA.war" 

configurations{ 
    deployerJars 
} 

repositories { 
    mavenCentral() 
} 

dependencies { 
    compile group: 'org.codehaus.jackson', name: 'jackson-core-asl', version: '1.9.3' 
    compile group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version: '1.9.3' 
    compile group: 'org.springframework', name: 'spring-core', version:'4.0.0.RELEASE' 
    compile group: 'org.springframework', name: 'spring-web', version:'4.0.0.RELEASE' 
    compile 'log4j:log4j:1.2.17' 
    compile 'com.sun.xml.ws:jaxws-rt:2.2.8' 
    compile 'org.jvnet.jax-ws-commons.spring:jaxws-spring:1.9' 
    compile group: 'org.springframework', name: 'spring-webmvc', version:'4.0.0.RELEASE' 
    providedCompile group: 'javax.servlet', name: 'servlet-api', version:'2.5' 
    testCompile group: 'junit', name: 'junit', version: '4.11' 
    deployerJars "org.apache.maven.wagon:wagon-http:2.2" 
} 

jar { 
    manifest { 
     attributes 'Implementation-Title': 'BLABLABLA', 'Implementation-Version': version 
    } 
} 

uploadArchives { 
    repositories { 
     flatDir { 
      dirs 'repos' 
     } 
    } 
} 


buildscript{ 
    repositories{ 
     jcenter() 
     mavenCentral() 
    } 
    dependencies { 
     classpath 'no.nils:wsdl2java:0.10' 
    } 
} 

wsdl2java{ 
    wsdlsToGenerate = [ 
      ["$projectDir/src/main/resources/BLABLABLA.wsdl"] 
    ] 
    generatedWsdlDir = file("$projectDir/src/gen/java") 
    wsdlDir = file("$projectDir/src/main/resources") 
} 

wsdl2javaExt { 
    cxfVersion = "2.5.1" 
} 

tasks.withType(Checkstyle) { 
    exclude '**/your/generated/package/goes/here**' 
} 

checkstyleMain.exclude '**/your/generated/package/goes/here**' 

“排除” 和 “checkstyleMain” 导致的错误,如“不能解析符号: -

apply plugin: 'war' 
apply plugin: 'jetty' 
apply plugin: 'checkstyle' 
apply plugin: 'java' 
apply plugin: 'no.nils.wsdl2java' 

sourceCompatibility = 1.7 
version = '1.0'  

... 

buildscript{ 
    repositories{ 
     jcenter() 
     mavenCentral() 
    } 
    dependencies { 
     classpath 'no.nils:wsdl2java:0.10' 
    } 
} 

task checkstyle(type: Checkstyle) { 
    source 'src' 
// include '**/*.java' 
// exclude '**/gen/**' 
// exclude '**/R.java' 
// exclude '**/BuildConfig.java' 
    exclude 'src/main/resources/generatedsources/**' 
} 

编辑后的建议(但仍然失败!) “!

+0

您是从Intellij还是从Gradle启动checkstyle? –

+0

@AndriiAbramov我怎么知道这个?我没有看到关于build.gradle的checkstyle的任何代码,除了我写代码来排除一些文件夹以防止checkstyle。 –

+0

你如何启动你的测试? –

回答

2

当应用checkstyle插件自定义任务都与它一起(见here)交付,所以不是添加自定义任务与Checkstyle型配置的发货之一。这是应该怎么做:

tasks.withType(Checkstyle) { 
    exclude '**/your/generated/package/goes/here**' 
} 

还可以配置一个特定的任务,还不是全部:

checkstyleMain.exclude '**/your/generated/package/goes/here**' 

而且,这不是很好的做法,把生成的源src/main/resources下。通常这些文件转到例如src/gen/java

+0

我应该把它们放入哪个文件中?的build.gradle?如果是,对于您的第一个建议,“排除”会出现错误,如“无法解析符号”。对于你的第二个建议,“checkstyleMain”也会给出同样的错误。 –

+0

是的,在'build.gradle'中,你在同一个文件中应用了checkstyle插件。你能分享整个'build.gradle'文件的变化导致问题? – Opal

+0

对不起,我刚刚复制了你的'build.gradle',它在我的工作站上工作。你正在使用什么gradle版本? – Opal

相关问题