2015-06-23 6 views
8

Android Studio kullanarak bir Android projesi oluşturuyorum. Uygulamanın build.gradle ekleyin: Özellik denetim kutusu yapılandırma dosyasında hata yok

apply from: '../config/quality.gradle' 

Sonra iki dosyalarla config dir oluşturun: quality.gradle gibi: gibi

apply plugin: 'checkstyle' 

task checkstyle(type: Checkstyle) { 
    configFile file("${project.rootDir}/config/checkstyle.xml") 
    source 'src' 
    include '**/*.java' 
    exclude '**/gen/**' 
    classpath = files() 
} 

Ve checkstyle.xml:

<?xml version="1.0"?> 
<!DOCTYPE module PUBLIC 
    "-//Puppy Crawl//DTD Check Configuration 1.3//EN" 
    "http://www.puppycrawl.com/dtds/configuration_1_3.dtd"> 

<module name="Checker"> 

    <module name="TreeWalker"> 

     <module name="NeedBraces"> 
      <property name="tokens" value="LITERAL_CASE, LITERAL_DEFAULT"/> 
      <property name="allowSingleLineStatement" value="true"/> 
     </module> 

    </module> 

</module> 

Running gradle checkstyle bana verir takip eden hata:

Executing external task 'checkstyle'... 
:app:checkstyle FAILED 

FAILURE: Build failed with an exception. 

* What went wrong: 
Execution failed for task ':app:checkstyle'. 
> Unable to create a Checker: cannot initialize module TreeWalker - Property 'allowSingleLineStatement' in module NeedBraces does not exist, please check the documentation 

* Try: 
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. 

BUILD FAILED 

çizgiyi kaldırırsanız:

çalışır
<property name="allowSingleLineStatement" value="true"/> 

. Ama documentation'u okurken, ilk versiyonu da çalışmalı.

O benzer olur: Yanlış veya ne şekilde yapıyorum

* What went wrong: 
Execution failed for task ':app:checkstyle'. 
> Unable to create a Checker: cannot initialize module TreeWalker - Unable to instantiate EmptyCatchBlock 

dokümanlar bu missunderstanding am:

<module name="EmptyCatchBlock"> 
    <property name="exceptionVariableName" value="expected|ignore"/> 
</module> 

beni atar mı?

cevap

16

Bu yazı yazıldığı zaman, Varsayılan olarak Grapes uses Checkstyle 5.9. allowSingleLineStatement özelliği yalnızca added in Checkstyle 6.5 idi. Yani, böyle bir yeni Checkstyle sürümünü kullanarak bu çalışma almak gerekir: Maalesef

checkstyle { 
    configFile = file("${project.rootDir}/config/checkstyle.xml") 
    toolVersion = '6.7' 
} 

, Checkstyle dokümantasyon sürüm bilgisi olmayan, bu nedenle İnternet sitesi her zaman zor bunu yapar sadece en son belgeler vardır Bunun gibi şeyler ortaya çıkar.

+0

'' file' anahtar sözcüğüyle 'configFile' yolundan önce çıkmam gerektiğine dikkat edin, ancak çözüm işe yaradı. Çok teşekkür ederim Thomas. – Birei

+0

Yup, 'configFile' bir' Dosya'; cevabımı buna göre güncelledi. Teşekkürler! –

+0

bu çözümü denedi, ancak IDEA bana 'Hata: (12, 0) Gradle: ': app' projesini değerlendirirken bir sorun oluştu. > Proje aracı argümanı için yöntem bulunamadı: (6.7) ': app'.' – pratt