Skip to content
New issue

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

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

Already on GitHub? # to your account

Gradle build error #1

Closed
JuNijland opened this issue Jul 28, 2016 · 5 comments
Closed

Gradle build error #1

JuNijland opened this issue Jul 28, 2016 · 5 comments

Comments

@JuNijland
Copy link

I followed all the steps for integrating ktlint into gradle
When adding the ktlint dependency to gradle, the following error occurs when building:

Execution failed for task ':compileFastDebugKotlin'
> com/intellij/ide/highlighter/JavaFileType
BUILD FAILED

screenshot from 2016-07-28 13-18-03

Using gradle 2.1.2 and ktlint 0.1.0
The commands gradle ktlint and gradle ktlintFormat do work from the command line, only building fails.

@shyiko
Copy link
Collaborator

shyiko commented Jul 28, 2016

Hi @JuNijland

I just tried building sample project using gradle 2.12 (I don't see 2.1.2 at https://gradle.org/gradle-download/) and ktlint 0.1.0 (running java 1.8.77 on on Arch Linux) using the following build.gradle

buildscript {
   ext.kotlin_version = '1.0.3'
   repositories {
     mavenCentral()
   }
   dependencies {
     classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
     classpath 'com.github.shyiko:ktlint:0.1.0'
   }
}

apply plugin: "kotlin"

repositories {
  mavenCentral()
}
dependencies {
  compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

task ktlint(type:JavaExec) {
    main = "com.github.shyiko.ktlint.Main"
    classpath = buildscript.configurations.classpath
    args "src/**/*.kt"
}

check.dependsOn ktlint

task ktlintFormat(type:JavaExec) {
    main = "com.github.shyiko.ktlint.Main"
    classpath = buildscript.configurations.classpath
    args "-F", "src/**/*.kt"
}

Works fine. Can you share you build configuration or something that could demonstrate the issue? Thank you.

@JuNijland
Copy link
Author

Hi,
Here is the full buildscript with the sensitive information left out.
We tested this on multiple dev environments of the same project, and we all had this issue

buildscript
{
    ext.kotlin_version = "1.0.0"
    ext.google_support_version = "24.0.0"
    ext.google_play_services = "9.0.2"
    ext.dokka_version = "0.9.8"
    ext.iconify_version = "2.2.2"

    repositories
    {
        mavenCentral()
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
        maven { url 'http://dl.bintray.com/content/aalmiray/kordamp' }
    }

    dependencies
    {
        classpath 'com.android.tools.build:gradle:2.1.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
        classpath 'io.fabric.tools:gradle:1.21.6'
        classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:${dokka_version}"
        classpath 'org.kordamp:markdown-gradle-plugin:1.0.0'
        classpath 'com.github.shyiko:ktlint:0.1.0'

    }
}

apply plugin: "com.android.application"
apply plugin: "kotlin-android"
apply plugin: "kotlin-android-extensions"
apply plugin: 'io.fabric'
apply plugin: 'org.jetbrains.dokka-android'
apply plugin: 'org.kordamp.markdown.convert'

repositories
{
    jcenter()
    mavenCentral()
    maven { url "https://jitpack.io" }
    maven { url 'https://maven.fabric.io/public' }
}

// TODO: zxing 3.1.+ needs support 23.*

dependencies
{
    compile "com.android.support:appcompat-v7:$google_support_version"
    compile "com.android.support:cardview-v7:$google_support_version"
    compile "com.android.support:design:$google_support_version"
    compile "com.android.support:support-v13:$google_support_version"
    compile "com.android.support:support-v4:$google_support_version"
    compile "com.google.android.gms:play-services:$google_play_services"
    compile "com.android.support:multidex:1.0.1"
    compile "com.davemorrissey.labs:subsampling-scale-image-view:3.4.1"
    compile "com.google.zxing:core:3.2.0"
    compile "com.journeyapps:zxing-android-embedded:3.0.2@aar"
    compile "com.joanzapata.iconify:android-iconify-fontawesome:$iconify_version"
    compile "com.joanzapata.iconify:android-iconify-material:$iconify_version"
    compile "com.joanzapata.iconify:android-iconify-material-community:$iconify_version"
    compile "me.leolin:ShortcutBadger:1.1.6@aar"
    compile "com.loopj.android:android-async-http:1.4.5"
    compile "com.mcxiaoke.volley:library:1.0.19"
    compile "com.squareup.okhttp:okhttp:2.2.0"
    compile "com.squareup.okhttp:okhttp-urlconnection:2.2.0"
    compile "com.facebook.android:facebook-android-sdk:4.8.0"
    compile "com.squareup.picasso:picasso:2.5.2"
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    compile "com.github.wenchaojiang:AndroidSwipeableCardStack:0.1.4"
    compile "com.daimajia.swipelayout:library:1.2.0@aar"
    compile "info.hoang8f:android-segmented:1.0.6"
    compile "com.github.chrisbanes:PhotoView:1.2.6"
    compile "com.theartofdev.edmodo:android-image-cropper:2.1.4"
    compile "com.karumi:dexter:2.2.2"
    compile "cz.advel.jbullet:jbullet:20101010-1"
    compile("com.crashlytics.sdk.android:crashlytics:2.5.5@aar") {
        transitive = true;
    }
    compile('io.fabric.sdk.android:fabric:1.3.10@aar') {
        transitive = true;
    }
}

android
{
    compileSdkVersion 23
    buildToolsVersion '23.0.3'

    useLibrary "org.apache.http.legacy"
    defaultConfig
    {
        targetSdkVersion 23
        multiDexEnabled true
        applicationId new File(".company-applicationid").text.trim()
        versionCode "git rev-list --count HEAD".execute().text as int // Amount of preceding commits
        versionName "git describe --tags --dirty".execute().text[1..-2] // strip v and newline

        // Example version names:
        // v5.5.0                  - A clean commit tagged v5.5.0
        // v5.5.0-2-gc0ffeed       - Two commits after v5.5.0 (this one has hash c0ffeed - the g means git)
        // v5.5.0-2-gc0ffeed-dirty - Same as above, but changes were made since last commit (the workspace is dirty)
    }

    signingConfigs
    {
        release
        {
            storeFile file("company-android.keystore")
            storePassword ""
            keyAlias ""
            keyPassword ""
        }
    }

    sourceSets
    {
        main.java.srcDirs += "src/main/kotlin" // Let Android Studio know there"s code here
    }

    buildTypes
    {
        debug
        {
            applicationIdSuffix ".debug"
            versionNameSuffix "-debug"
        }

        release
        {
            //minifyEnabled true
            proguardFile getDefaultProguardFile('proguard-android.txt')
            proguardFile 'proguard-project.txt'
            signingConfig signingConfigs.release
        }
    }

    productFlavors
    {
        fast
        {
            minSdkVersion 16
            dexOptions {
                preDexLibraries = false
            }
        }

        slow
        {
            minSdkVersion 16
        }
    }

    applicationVariants.all { variant ->
        variant.resValue "string", "version", "v" + variant.versionName + " (" + variant.versionCode + ")"

        // Version tag used by Client. Does not affect versionName.
        variant.buildConfigField "String", "VERSION_TAG", "\"" +
        (
            (System.getenv("GRADLE_VERSION_TAG")) ? System.getenv("GRADLE_VERSION_TAG")
                                                  : "git describe --tags --abbrev=0".execute().text[1..-2]
        ) + "\""

        // Output to a specific path. Used by build.rb to install app after build.
        if (System.getenv("GRADLE_APK_OUTPUT_PATH"))
        {
            variant.outputs.each { output ->
                output.outputFile = file(System.getenv("GRADLE_APK_OUTPUT_PATH"))
            }
        }
    }
}

//https://kotlinlang.org/docs/reference/kotlin-doc.html
dokka {
    moduleName = 'Company-Android'
    outputFormat = 'javadoc'
    outputDirectory = "$buildDir/javadoc"
    processConfigurations = ['compile', 'extra']
    linkMapping {
        dir = "src/main/kotlin"
        url = "https://bitbucket.org/project"
        suffix = "#-"
    }
    sourceDirs = files('src/main/kotlin')
}

markdownToHtml {
    sourceDir = file('docs/')
}

task ktlint(type:JavaExec) {
    main = "com.github.shyiko.ktlint.Main"
    classpath = buildscript.configurations.classpath
    args "src/**/*.kt"
}

check.dependsOn ktlint

task ktlintFormat(type:JavaExec) {
    main = "com.github.shyiko.ktlint.Main"
    classpath = buildscript.configurations.classpath
    args "-F", "src/**/*.kt"
}


// Log timings per task.
class TimingsListener implements TaskExecutionListener, BuildListener {
    private Clock clock
    private timings = []

    @Override
    void beforeExecute(Task task) {
        clock = new org.gradle.util.Clock()
    }

    @Override
    void afterExecute(Task task, TaskState taskState) {
        def ms = clock.timeInMs
        timings.add([ms, task.path])
        task.project.logger.warn "${task.path} took ${ms}ms"
    }

    @Override
    void buildFinished(BuildResult result) {
        println "Task timings:"
        for (timing in timings) {
            if (timing[0] >= 50) {
                printf "%7sms  %s\n", timing
            }
        }
    }

    @Override
    void buildStarted(Gradle gradle) {}

    @Override
    void projectsEvaluated(Gradle gradle) {}

    @Override
    void projectsLoaded(Gradle gradle) {}

    @Override
    void settingsEvaluated(Settings settings) {}
}

gradle.addListener new TimingsListener()

@JuNijland
Copy link
Author

I just tried updating to kotlin version 1.0.3 which seemed to fix the problem.

@shyiko
Copy link
Collaborator

shyiko commented Jul 28, 2016

Thanks @JuNijland. readme.md updated. Now it should work regardless of Kotlin compiler version.

@shyiko shyiko closed this as completed Jul 28, 2016
@JuNijland
Copy link
Author

Yes verified. Thanks!

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

No branches or pull requests

2 participants