kordamp / enforcer-gradle-plugin

Kordamp Enforcer Gradle Plugin
Apache License 2.0
23 stars 3 forks source link

[question] can`t force DependencyConvergence rule to work #29

Closed pshakhov closed 1 year ago

pshakhov commented 1 year ago

Hello! I have a problem with usage of DependencyConvergence rule.

settings.gradle.kts:

buildscript {
    repositories {
        gradlePluginPortal()
    }
    dependencies {
        classpath("org.kordamp.gradle:enforcer-gradle-plugin:0.13.0")
    }
}
apply(plugin = "org.kordamp.gradle.enforcer")

rootProject.name = "enforcer-gragle-plugin-example"

build.gradle.kts:

import enforcer.rules.BannedDependencies
import enforcer.rules.DependencyConvergence
import org.kordamp.gradle.plugin.enforcer.api.EnforcerLevel

plugins {
    `java-library`

    id("org.kordamp.gradle.project-enforcer")
}

group = "org.example"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

apply(plugin = "org.kordamp.gradle.project-enforcer")

enforce {

    // can`t force to work
  rule(DependencyConvergence::class.java) {
      failOnDynamicVersions.set(true)
      failOnChangingVersions.set(true)
      failOnNonReproducibleResolution.set(true)
  }

  // works as expected
  rule(BannedDependencies::class.java) {
      enforcerLevel.set(EnforcerLevel.WARN)
      exclude("org.slf4j:slf4j-api")
  }
}

dependencies {
    testImplementation(platform("org.junit:junit-bom:5.9.1"))
    testImplementation("org.junit.jupiter:junit-jupiter")

    implementation("org.slf4j:slf4j-jdk14:1.6.1")
    implementation("org.slf4j:slf4j-nop:1.6.0")
}

tasks {
    test {
        useJUnitPlatform()
    }

    wrapper {
        gradleVersion = "6.8.2"
    }
}

Getting log for BannedDependencies rule: `

Configure project : [project-enforcer :] [AFTER_PROJECT :] An Enforcer rule has failed org.kordamp.gradle.plugin.enforcer.api.EnforcerRuleException: Enforcer rule 'enforcer.rules.BannedDependencies' was triggered. Found Banned Dependency: org.slf4j:slf4j-api:1.6.1 in project : Disable this rule temporarily with -Denforcer.rules.BannedDependencies.enabled=false and invoke 'dependencies' to locate the source of the banned dependencies. `

but if disable it and use only DependencyConvergence rule or both configuration not fails.

What Am I Doing Wrong? Can push minimal, reproducible Example if needed.

aalmiray commented 1 year ago

FWIW you don't have to configure both enforcer plugins. For what I can see use only the project-enforcer for the time being.

pshakhov commented 1 year ago

enforce extension used like in doc example can`t resolve in settings file:

image