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

Unable to specify importOrder #125

Closed
srikanthanusuri opened this issue Jul 25, 2017 · 4 comments
Closed

Unable to specify importOrder #125

srikanthanusuri opened this issue Jul 25, 2017 · 4 comments
Assignees
Labels

Comments

@srikanthanusuri
Copy link

I am seeing the following issue when I run a build. Is there something that I am missing to add to the configuration?

* What went wrong:
A problem occurred evaluating root project 'my-app'.
> No such property: importOrder for class: com.diffplug.gradle.spotless.JavaExtension

The contents of my build.gradle file is as follows.

buildscript {
    repositories {
        jcenter()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath 'com.diffplug.spotless:spotless-plugin-gradle:3.4.1'
    }
}

apply plugin: 'java'
apply plugin: 'com.diffplug.gradle.spotless'

spotless {
    java {
      importOrder ['java', 'javax', 'org', 'com', 'com.diffplug', '']
      removeUnusedImports()
    }
}

Project directory structure:

├───.gradle
│   └───2.14
│       └───taskArtifacts
├───gradle
│   └───wrapper
└───src
    ├───main
    │   ├───java
    │   │   └───com
    │   │       └───test
    │   └───resources
    └───test
        ├───java
        └───resources

The debug output has been attached here
The stacktrace can be found here

@fvgh
Copy link
Member

fvgh commented Jul 25, 2017

Just as a way forward, using parentheses should work:
importOrder(['java', 'javax', 'org', 'com', 'com.diffplug', ''])

E.g. Groovy (and that is basically what interprets the Gradle script) allows you to omit parentheses

when there is no ambiguity

There is a problem when it interprets the square brackets as an index though. I will have a detailed look later on.

Let me know, if the work-around suits you for now.

@fvgh
Copy link
Member

fvgh commented Jul 25, 2017

@nedtwigg Seems to me that Groovy always interpreted that syntax as a multidimensional index (trying to call getAt), well at least since version 2.3.
According to the spotless history, the code had not changed for quite some time. Was there always an error in the documentation?
In this case I propose following change:

  1. Mark current interface as deprecated
  2. Add importOrder(String... order)
  3. Update tests and documentation

OK for you?

@fvgh fvgh self-assigned this Jul 25, 2017
@fvgh fvgh added the bug label Jul 25, 2017
@srikanthanusuri
Copy link
Author

Thanks guys! Appreciate the quick feedback.

@nedtwigg
Copy link
Member

It's so great to have a Groovy expert onboard, @fvgh! That part of the docs goes all the way back to April 2015 - could well have been wrong the whole time. Regardless, your fix sounds good to me 👍

nedtwigg added a commit that referenced this issue Jul 28, 2017
Replaced importOrder array argument by varargs. Fixes #125.
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

3 participants