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

ktlintFormat creates directories under src #423

Closed
red-avtovo opened this issue Dec 29, 2020 · 6 comments · Fixed by #520
Closed

ktlintFormat creates directories under src #423

red-avtovo opened this issue Dec 29, 2020 · 6 comments · Fixed by #520
Labels

Comments

@red-avtovo
Copy link

When I run ktlintFormat there are the following directories, which are created under src directory:

  • src/main/java
  • src/main/kotlin
  • src/test/java
  • src/test/kotlin

It is pretty annoying seeing java directory all the time and have no chance to get rid of it when you write a 100% Kotlin project. Is there a way to ask ktlint not to create these directories?

@Tapchicoma
Copy link
Collaborator

Are you sure that it is ktlint-gradle who creates this directories?

Generally this plugin only modifies files without creating any SourceSet and related directories, plus I haven't seen such behaviour in my other projects that apply this plugin.

Maybe you could create some project to reproduce it or share your project?

@red-avtovo
Copy link
Author

Here you go: https://github.com/red-avtovo/ktlintTest
If you will pull the repo and run ./gradlew ktlintFormat it will create a java directory under src

@red-avtovo
Copy link
Author

red-avtovo commented Jan 5, 2021

Some additional info: when you run ktlintFormat these tasks are being executed as dependencies

./gradlew ktlintFormat --dry-run
:ktlintKotlinScriptFormat SKIPPED
:ktlintMainSourceSetFormat SKIPPED
:ktlintTestSourceSetFormat SKIPPED
:ktlintFormat SKIPPED

When I call just ./gradlew :ktlintMainSourceSetFormat java directory is already being created

@JLLeitschuh
Copy link
Owner

JLLeitschuh commented Jan 5, 2021

This may be because we are declaring the source sets to be both inputs and outputs. As such, Gradle has a CreateOutputsStep processor that runs on tasks to automatically generate the output directories for the task. Since for the Format task, the inputs and outputs are the same, Gradle ends up generating these directories.

Semi-related:
gradle/gradle#15679

@Tapchicoma
Copy link
Collaborator

Could reproduce this issue with sample project 👍

Relates to #306

@ed0906
Copy link

ed0906 commented Feb 22, 2021

We also have this issue
Temporary workaround is to just delete the extra folders immediately after

tasks {
    ktlintFormat {
        doLast {
            delete("src/main/java")
            delete("src/test/java")
            // etc
        }
    }
}

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