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

Confused about IntelliJ IDEA/Android Studio integration #348

Open
ColtonIdle opened this issue Mar 19, 2020 · 13 comments
Open

Confused about IntelliJ IDEA/Android Studio integration #348

ColtonIdle opened this issue Mar 19, 2020 · 13 comments
Labels

Comments

@ColtonIdle
Copy link

I have a plain and simple configuration setup. In the root of my AS project I have:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = "1.3.70"
    repositories {
        google()
        jcenter()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.0.0-beta02"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jlleitschuh.gradle:ktlint-gradle:9.2.1"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

subprojects {
    apply plugin: "org.jlleitschuh.gradle.ktlint"
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

apply plugin: "org.jlleitschuh.gradle.ktlint"

I would love if my project could now have a codestyle set in intelliJ that allows me to cmd + shift + L to reformat as per the ktlint rules.

Looking at the readme I'm confused:

It says:

IntelliJ Idea Only Plugin
Note: This plugin is automatically applied by the main ktlint plugin.

This plugin just adds special tasks that can generate IntelliJ IDEA codestyle rules using ktlint.

Idea plugin simple setup
For all gradle versions:

Use the same buildscript logic as above, but with this instead of the above suggested apply line.

apply plugin: "org.jlleitschuh.gradle.ktlint-idea"

  1. So it looks like for the IntelliJ plugin, I don't have to do anything since it's applied "by the main ktlint". I'm not sure if this is a gradle plugin or is this an IntelliJ IDEA plugin. If I go to the IntelliJ Plugin marketplace, I don't see anything about a plugin being installed

  2. If "This plugin is automatically applied by the main ktlint plugin." then why does it say right below to " Use the same buildscript logic as above, but with this instead of the above suggested apply line.

apply plugin: "org.jlleitschuh.gradle.ktlint-idea""

Appreciate any clarification here or on the readme that get's me to my goal of cmd + shift + L to reformat as per the ktlint rules in my project, so that we can share via git in my teams project

@JLLeitschuh
Copy link
Owner

It's a plugin for Gradle that will configure IJ to conform to the Ktlint format settings.

@ColtonIdle
Copy link
Author

@JLLeitschuh
So if I want to use ktlint in my intellij project, it akes sense that I would have BOTH plugins?

i.e.

apply plugin: "org.jlleitschuh.gradle.ktlint"
apply plugin: "org.jlleitschuh.gradle.ktlint-idea"

After I apply the idea plugin, when does it actually "configure IJ to conform to the Ktlint format settings". Every time I hit build in intellij?

@JLLeitschuh
Copy link
Owner

See: https://github.com/JLLeitschuh/ktlint-gradle#additional-helper-tasks

Your IDE will only be configured if you run one of the two IDEA specific tasks.

@ColtonIdle
Copy link
Author

Aha. That's where my confusion came in. When I read the docs for ktlintApplyToIdea I thought that I could run that task with only apply plugin: "org.jlleitschuh.gradle.ktlint", but it sounds like you're saying I still need the apply plugin: "org.jlleitschuh.gradle.ktlint-idea" line as well.

Then, I need to instruct everyone on my team to run ktlintApplyToIdea.

@JLLeitschuh
Copy link
Owner

If I set it up right, "org.jlleitschuh.gradle.ktlint" should automatically apply the "org.jlleitschuh.gradle.ktlint-idea" plugin automatically.

@ColtonIdle
Copy link
Author

Oh. So no need for me to apply two plugins? Only apply plugin: "org.jlleitschuh.gradle.ktlint"?

Not too clear from the docs, but I can try this out and let you know the behavior, now that you clarified what the intended behavior is.

@JLLeitschuh
Copy link
Owner

I thought I had documented it at one point, @Tapchicoma what happened to the 'what plugin is applied' documentation? Did that get removed at some point?

@Tapchicoma
Copy link
Collaborator

@JLLeitschuh could not recall if I removed it or it was missing initially

@ColtonIdle this integration from ktlint side is quite limited, see pinterest/ktlint#701

@ColtonIdle
Copy link
Author

@Tapchicoma oh wait? Shit. Really?

This really sucks. I really want cmd + shift + L for my teammates to all do the same thing AND to adhere to ktlint.

From what it sounds like... this is not possible? Am I interpreting this correctly @Tapchicoma ?

@Tapchicoma
Copy link
Collaborator

@ColtonIdle sorry for a late reply.

Yep currently it is not possible. If linked ticket would be implemented - this should solve your issue.

@ColtonIdle
Copy link
Author

@Tapchicoma thanks. I thought I was going crazy.

@u-ways
Copy link

u-ways commented Aug 22, 2021

@ColtonIdle bit late to the party but what did your team decide to do? Did you end up using Ktlint in your project? Did you instruct everyone on your team to run ktlintApplyToIdea or did you figure out a better way? I would appreciate your insight and guidance.

@ColtonIdle
Copy link
Author

@u-ways we moved to ktfmt. It's based off of googles java formatter and so it inherits any fixes from there, which makes for more frequent releases + a supported intellij plugin was perfect for our team.

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

No branches or pull requests

4 participants