Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when running Lint task #3

Closed
vRallev opened this issue May 29, 2017 · 4 comments
Closed

Crash when running Lint task #3

vRallev opened this issue May 29, 2017 · 4 comments

Comments

@vRallev
Copy link

vRallev commented May 29, 2017

I've tried to use the plugin in our Android project. We usually extract common scripts in separate files and there the plugin is crashing

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:kotlinLint'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:98)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:68)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
        at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:46)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:236)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:228)
        at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:61)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:228)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:215)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:77)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:58)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
        at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:46)
Caused by: org.gradle.api.UnknownDomainObjectException: Extension of type 'KotlinterExtension' does not exist. Currently registered extension types: [ExtraPropertiesExtension, DefaultArtifactPublicationSet, ReportingExtension, AppExtension, KotlinProjectExtension, KaptExtension, KotlinterExtension, DownloadExtension, UnMockExtension]
        at org.gradle.api.internal.plugins.ExtensionsStorage.getHolderByType(ExtensionsStorage.java:91)
        at org.gradle.api.internal.plugins.ExtensionsStorage.getByType(ExtensionsStorage.java:78)
        at org.gradle.api.internal.plugins.DefaultConvention.getByType(DefaultConvention.java:171)
        at org.gradle.api.internal.plugins.DefaultConvention.getByType(DefaultConvention.java:166)
        at org.jmailen.gradle.kotlinter.tasks.LintTask.ignoreFailures(LintTask.kt:23)
        at org.jmailen.gradle.kotlinter.tasks.LintTask.run(LintTask.kt:53)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
        at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.doExecute(DefaultTaskClassInfoStore.java:141)
        at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
        at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:123)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:692)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:675)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.execute(ExecuteActionsTaskExecuter.java:115)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.execute(ExecuteActionsTaskExecuter.java:109)
        at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:56)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:109)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:90)
        ... 20 more

The main build script looks something like this

apply some plugins
android { }
apply from: '../gradle/kotlin-lint.gradle' // apply after the android plugin has been configured

The apply from is the problem. If I copy the following script inside of the file, then the task is successful.

That's the complete kotlin-lint.gradle file

import org.jmailen.gradle.kotlinter.tasks.LintTask

kotlinter {
    ignoreFailures = false
}

// buildscript is necessary to find the imports
buildscript {
    repositories {
        jcenter()

        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }

    dependencies {
        classpath "gradle.plugin.org.jmailen.gradle:kotlinter-gradle:$kotlinLintVersion"
    }

    // Enable this in case the gradle plugin is using an older version
    //
    // configurations.classpath {
    //     resolutionStrategy { force 'com.github.shyiko:ktlint:0.6.1' }
    // }
}

apply plugin: 'org.jmailen.kotlinter'

kotlinter {
    // this block does not help
    ignoreFailures = false
}

task kotlinLint(type: LintTask, group: 'verification') {
    FileTree tree = files().asFileTree

    android.sourceSets.each { sourceSet ->
        sourceSet.javaDirectories.each {
            tree += fileTree(dir: it, include: '**/*.kt')
        }
    }

    source tree

    report = file('build/lint-report.txt')
}

check.dependsOn kotlinLint
@jeremymailen
Copy link
Owner

Thanks for the report and digging into it. I'll take a look.

@jeremymailen
Copy link
Owner

jeremymailen commented May 30, 2017

I think I've addressed the issue. Please give release 0.8.1 a try and let me know if it works.

Please note that buildscript blocks in externally included gradle scripts have incomplete behavior. The original failure was due to the kotlinter extension not being in scope for that reason.
See gradle/gradle#1323 for some similar struggles people have had.

Now ignoreFailures is just an ordinary boolean property of LintTask. I apply the value of the extension property to whatever tasks are in the project scope, but if you declare your lint task in an externally included gradle script I think you'll still need to do this as it won't pick up the extension:

task kotlinLint(type: LintTask, group: 'verification') {
...
    source tree

    report = file('build/lint-report.txt')

    ignoreFailures true
}

Note that ignoreFailures false is the default.

@vRallev
Copy link
Author

vRallev commented May 30, 2017

Yes, that works. Thanks!

@vRallev vRallev closed this as completed May 30, 2017
@arulrajnet
Copy link

buildscript {
    repositories {
        jcenter()

        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
}

Add this into build.gradle. It will solve your plugin scope problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants