séa*_*n35 6 java intellij-idea checkstyle gradle
我是IntelliJ和Gradle的新手,但是我有足够的Java和Eclipse经验。我从wsdl文件生成了一些Java类。我将它们放在src/main/resources文件夹名称下-“ generatedsources”。
我试图防止此文件夹及其子文件夹的checkstyle像src/main/resources/generatedsources/*IntelliJ上的gradle 一样。
我尝试了一些这样的方法;
task checkstyle(type: Checkstyle) {
source 'src'
// include '**/*.java'
// exclude '**/gen/**'
// exclude '**/R.java'
// exclude '**/BuildConfig.java'
exclude 'src/main/resources/generatedsources/**'
}
Run Code Online (Sandbox Code Playgroud)
但是我又失败了。
build.gradle;
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/**'
}
Run Code Online (Sandbox Code Playgroud)
编辑-推荐之后(但仍然失败!):
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**'
Run Code Online (Sandbox Code Playgroud)
task.withType和“ checkstyleMain”中的“ exclude”会导致错误,例如“无法解析符号”!
当checkstyle插件应用自定义任务与它一起(见交付这里),所以不是添加自定义任务类型,Checkstyle配置运之一。这是应该做的:
tasks.withType(Checkstyle) {
exclude '**/your/generated/package/goes/here**'
}
Run Code Online (Sandbox Code Playgroud)
您还可以配置特定的任务,而不是全部:
checkstyleMain.exclude '**/your/generated/package/goes/here**'
Run Code Online (Sandbox Code Playgroud)
同样,将生成的源置于以下也不是一个好习惯src/main/resources。通常,此类文件会转到例如src/gen/java
我遵循了一些评论并使其正常工作,将其添加到文件中build.gradle
checkstyle {
config = rootProject.resources.text.fromFile("${project.projectDir}/checkstyle-8.34_google_checks.xml")
toolVersion = '8.34'
ignoreFailures = false
maxWarnings = 0
}
checkstyleMain
.exclude('com/examples/gen/api/*.java')
.exclude('com/examples/gen/model/*.java')
.exclude('com/examples/gen/auth/*.java')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8381 次 |
| 最近记录: |