2015-06-23 21 views
8

Creo un progetto Android utilizzando Android Studio. Nel build.gradle della App Aggiungi:La proprietà non esiste errore nel file di configurazione checkstyle

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

Poi ho creare la config dir con due file: quality.gradle come:

apply plugin: 'checkstyle' 

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

E checkstyle.xml come:

<?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> 

Esecuzione gradle checkstyle mi dà errore seguente:

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 

Se rimuovo linea:

<property name="allowSingleLineStatement" value="true"/> 

funziona. Ma leggendo il documentation, dovrebbe funzionare anche la prima versione.

Succede simile con:

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

Che cosa sto facendo di sbagliato o in che modo sto missunderstanding la documentazione:

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

che mi getta?

risposta

16

Al momento della stesura, Gradle uses Checkstyle 5.9 per impostazione predefinita. La proprietà allowSingleLineStatement era solo added in Checkstyle 6.5. Quindi, si dovrebbe essere in grado di ottenere questo lavoro utilizzando una versione più recente Checkstyle come questo:

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

Purtroppo, la documentazione Checkstyle non è sotto controllo di versione, in modo che il sito ha sempre gli ultimi documenti solo, il che rende difficile figure come questa.

+0

Nota che ho dovuto precedere il percorso di 'configFile' con la parola chiave' file', ma la soluzione ha funzionato. Grazie mille, Thomas. – Birei

+0

Yup, 'configFile' è un' File'; aggiornato la mia risposta di conseguenza. Grazie! –

+0

provato questa soluzione, ma IDEA mi mostra che 'Errore: (12, 0) Gradle: si è verificato un problema nella valutazione del progetto ': app'. > Impossibile trovare il metodo toolVersion() per gli argomenti [6.7] sul progetto ': app'. – pratt

Problemi correlati