aboutsummaryrefslogtreecommitdiff
path: root/dokka-runners/dokkatoo/buildSrc/src/main/kotlin/buildsrc/conventions/gradle-plugin-variants.gradle.kts
blob: 1d9fc43b01e2481ed67768886445ff88c1518628 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package buildsrc.conventions

import org.gradle.api.attributes.plugin.GradlePluginApiVersion.GRADLE_PLUGIN_API_VERSION_ATTRIBUTE

plugins {
  id("buildsrc.conventions.base")
  `java-gradle-plugin`
}

fun registerGradleVariant(name: String, gradleVersion: String) {
  val variantSources = sourceSets.create(name)

  java {
    registerFeature(variantSources.name) {
      usingSourceSet(variantSources)
      capability("${project.group}", "${project.name}", "${project.version}")

      withJavadocJar()
      withSourcesJar()
    }
  }

  configurations
    .matching { it.isCanBeConsumed && it.name.startsWith(variantSources.name) }
    .configureEach {
      attributes {
        attribute(GRADLE_PLUGIN_API_VERSION_ATTRIBUTE, objects.named(gradleVersion))
      }
    }

  tasks.named<Copy>(variantSources.processResourcesTaskName) {
    val copyPluginDescriptors = rootSpec.addChild()
    copyPluginDescriptors.into("META-INF/gradle-plugins")
//        copyPluginDescriptors.into(tasks.pluginDescriptors.flatMap { it.outputDirectory })
    copyPluginDescriptors.from(tasks.pluginDescriptors)
  }

  dependencies {
    add(variantSources.compileOnlyConfigurationName, gradleApi())
  }
}

registerGradleVariant("gradle7", "7.6")
registerGradleVariant("gradle8", "8.0")