plugins {
    id 'java-library'
}

repositories {
    mavenCentral()
}

// tag::dependencies[]
dependencies {
    // a dependency on Jackson Databind
    implementation 'com.fasterxml.jackson.core:jackson-databind:2.8.9'

    // and a dependency on vert.x
    implementation 'io.vertx:vertx-core:3.5.3'
}
// end::dependencies[]

// tag::use_rule[]
dependencies {
    components.all(JacksonAlignmentRule)
}
// end::use_rule[]

// tag::enforced_platform[]
dependencies {
    // Forcefully downgrade the Jackson platform to 2.8.9
    implementation enforcedPlatform('com.fasterxml.jackson:jackson-platform:2.8.9')
}
// end::enforced_platform[]

// tag::alignment-rule[]
class JacksonAlignmentRule implements ComponentMetadataRule {
    void execute(ComponentMetadataContext ctx) {
        ctx.details.with {
            if (id.group.startsWith("com.fasterxml.jackson")) {
                // declare that Jackson modules all belong to the Jackson virtual platform
                belongsTo("com.fasterxml.jackson:jackson-platform:${id.version}")
            }
        }
    }
}
// end::alignment-rule[]
