question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add targetExclude to plugin-gradle README

See original GitHub issue

My project (using Gradle) has a task which generates some Scala sources, and I add generated source directories to the scala source set:

        project.extensions.findByType<SourceSetContainer>()?.invoke {
            "main" {
                withConvention(ScalaSourceSet::class) {
                    scala {
                        srcDir(project.generatedScalaDirectory)
                    }
                }
            }
        }

        val Project.generatedScalaDirectory: Provider<Directory>
            get() = layout.buildDirectory.dir("generated-scala")

I don’t really care about generated sources formatting, because they are generated upon each compilation to the build directory, and are not committed to the repository. But as I’ve just discovered, spotless check (with its scalafmt support) fails on these generated sources.

Since I don’t really want these sources to be checked, I would prefer for there to be a way to set up and exclude clause, something like

spotless {
    scala {
        scalafmt().configFile("${project.rootDir}/.scalafmt.conf")
        exclude(project.generatedScalaDirectory)
    }
}

However, it appears that there is no way to do it. It seems that there are two options:

  1. Use ignoreErrorForPath to specify a path to the excluded file.

    This does not appear to work: I still get a failed build, regardless of what path I specify with this method. Its sources indicate that it expects a “relative path”, but it is not really clear relative to where it should be; it does not seem to be the project directory or root project directory.

    Anyway, this approach does not scale because it seems that it requires all files to be specified, separately, and not just the enclosing directory, which does not really scale.

  2. Use the target method to explicitly specify only the src/main/scala and src/test/scala sources.

    This is suboptimal, because I want to exclude something. This means that I have to remember to add new directories, e.g. new source sets, say, integrationTest, or I risk silently losing style verification for them.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
nedtwiggcommented, Feb 10, 2019

I added targetExclude in #353. I resolved the ambiguities in this way: the files that get formatted are target - targetExclude. When you call target, you wipe out any previous calls. Same with targetExclude.

Implementing this change is just a few lines of code, but it actually affects 2 other issues. For this reason I’m closing this issue out so that the discussion can continue in the PR. If the PR meets the needs of all the issues, then I’ll merge and we’ll be all set.

1reaction
nedtwiggcommented, Feb 12, 2019

Published in 3.18.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

diffplug/spotless - Gitter
Hello! I've integrated spotless with Checkstyle in my project. There are few java files which Spotless ignores (might be because of the module...
Read more >
Gradle - GitHub
Quickstart To use it in your buildscript, just [add the Spotless ... /6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.
Read more >
FormatExtension (plugin-gradle 5.6.1 API) - Javadoc.io
Sets which files should be formatted. Files to be formatted = (target - targetExclude). When this method is called multiple times, only the...
Read more >
README.md · master - Gemnasium Gradle Plugin - GitLab
This plugin was developed in order to add dependency scanning support for Gradle projects to GitLab and will be used by the GitLab...
Read more >
FINERACT-1188: README and other files are not covered by ...
The following commit(s) were added to refs/heads/develop by this push: ... https://github.com/diffplug/spotless/tree/main/plugin-gradle + ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found