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?
Nota che ho dovuto precedere il percorso di 'configFile' con la parola chiave' file', ma la soluzione ha funzionato. Grazie mille, Thomas. – Birei
Yup, 'configFile' è un' File'; aggiornato la mia risposta di conseguenza. Grazie! –
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