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

Adding Detekt to a project from scratch, detektGenerateConfig is broken #2549

Closed
rock3r opened this issue Mar 29, 2020 · 2 comments · Fixed by #2550
Closed

Adding Detekt to a project from scratch, detektGenerateConfig is broken #2549

rock3r opened this issue Mar 29, 2020 · 2 comments · Fixed by #2550
Labels
Milestone

Comments

@rock3r
Copy link
Contributor

rock3r commented Mar 29, 2020

Expected Behavior

The task should generate the config for Detekt in a new project when run

Observed Behavior

The task fails with error:

Could not determine the dependencies of task ':detektGenerateConfig'.
> Could not resolve all task dependencies for configuration ':detekt'.
   > Cannot resolve external dependency io.gitlab.arturbosch.detekt:detekt-cli:1.7.2 because no repositories are defined.
     Required by:
         project :

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

Yes, the required by and project fields are actually empty, I didn't omit anything.

Steps to Reproduce

Added to an existing codebase with a composite build structure. Structure:

<root>
  - composite build: A
    - module A1
    - module A2...
  - composite build: B
    - module B1...
  - composite build: C
  - composite build: D

I am currently operating from the root project, but adding Detekt to composite build A. Operating directly from project A's folder (so this is now from Gradle's perspective any regular project) yields the same result.

Context

Haven't tried any other tasks yet — I can't even get the build to generate the config file, so not much of a point to. I have followed the "getting started" section on the website, so I have added to composite build A's build.gradle.kts:

import io.gitlab.arturbosch.detekt.*
import kpm.server.gradle.*
import org.gradle.kotlin.dsl.detekt
import org.jetbrains.kotlin.gradle.tasks.*

buildscript {
    repositories {
        jcenter()
    }
}

plugins {
    `java-library`
    id("org.jetbrains.kotlin.jvm") apply false
    id("com.github.ben-manes.versions") version "0.28.0"
    id("io.gitlab.arturbosch.detekt") version "1.7.2"
}

// ...

subprojects {
    buildscript {
        repositories {
            jcenter()
        }
    }

    apply(plugin = "io.gitlab.arturbosch.detekt")

    // ...

    repositories {
        maven(url = "https://dl.bintray.com/kotlin/ktor")
        maven(url = "https://dl.bintray.com/kotlin/kotlinx")
        maven(url = "https://dl.bintray.com/kotlin/kotlinx.html")

        // ... private repos

        mavenCentral()
        jcenter()
    }

    detekt {
        toolVersion = "1.7.2"
    }

    dependencies {
        // ... other dependencies
        detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.7.2")
    }

    tasks.withType<Detekt> {
        this.jvmTarget = "1.8"
    }

    // ...
}

Your Environment

  • Version of detekt used: 1.7.2
  • Version of Gradle used (if applicable): 6.3
  • Operating System and version: macOS Catalina
  • Link to your project (if it's a public repository): N/A
@rock3r
Copy link
Contributor Author

rock3r commented Mar 29, 2020

I have tested down to v1.5.0, and the same thing happens...

@rock3r
Copy link
Contributor Author

rock3r commented Mar 29, 2020

Eureka! Got it to work. I don’t have jcenter() on my non-buildscript repositories list; the plugin fails to add it if it’s missing… should be a relatively straightforward fix at least :)

rock3r added a commit to rock3r/detekt that referenced this issue Mar 29, 2020
Whenever the plugin is applied to a project that doesn't have
jcenter() configured, the user would get a cryptic error message
from Gradle (see issue detekt#2549). This simple change makes sure the
plugin will provide users with clear instructions on how to fix
their build so they don't get stumped when things don't work.
arturbosch pushed a commit that referenced this issue Mar 29, 2020
* Emit helpful errors in Gradle plugin

Whenever the plugin is applied to a project that doesn't have
jcenter() configured, the user would get a cryptic error message
from Gradle (see issue #2549). This simple change makes sure the
plugin will provide users with clear instructions on how to fix
their build so they don't get stumped when things don't work.

* Update contributions in README

* Fix ktlint name in docs: it's all lowercase

Also update repo URL to /pinterest/ktlint through out docs

* Update Gradle getting started in index.md

* Fix ktlint name in code too

* Address detekt warnings after plugin changes

* Only check for jCenter in afterEvaluate { }

This is necessary because we need to make sure it's there _somehow_,
and it may be added by other plugins, or blocks evaluated after this
plugin is applied.

* Apply suggestions from code review

Co-Authored-By: M Schalk <30376729+schalkms@users.noreply.github.com>

Co-authored-by: M Schalk <30376729+schalkms@users.noreply.github.com>
@arturbosch arturbosch added this to the 1.8.0 milestone Mar 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants