Skip to content

Commit

Permalink
build: Introduce a convention plugin for plugins
Browse files Browse the repository at this point in the history
Introduce the new `ort-plugin-conventions` plugin to simplify the
configuration of plugin projects.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
  • Loading branch information
mnonnenmacher committed Aug 29, 2024
1 parent 1e9ae8a commit b82a5c1
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 38 deletions.
1 change: 1 addition & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ dependencies {
implementation(libs.plugin.dokkatoo)
implementation(libs.plugin.graalVmNativeImage)
implementation(libs.plugin.kotlin)
implementation(libs.plugin.ksp)
implementation(libs.plugin.mavenPublish)
}
31 changes: 31 additions & 0 deletions buildSrc/src/main/kotlin/ort-plugin-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2024 The ORT Project Authors (see <https://github.com/oss-review-toolkit/ort/blob/main/NOTICE>)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
* License-Filename: LICENSE
*/

plugins {
// Apply precompiled plugins.
id("ort-library-conventions")
id("ort-publication-conventions")

// Apply third-party plugins.
id("com.google.devtools.ksp")
}

dependencies {
ksp(project(":plugins:compiler"))
}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ download = { id = "de.undercouch.download", version.ref = "downloadPlugin" }
gitSemver = { id = "com.github.jmongard.git-semver-plugin", version.ref = "gitSemverPlugin" }
ideaExt = { id = "org.jetbrains.gradle.plugin.idea-ext", version.ref = "ideaExtPlugin" }
kotlinSerialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlinPlugin" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
versions = { id = "com.github.ben-manes.versions", version.ref = "versionsPlugin" }

[libraries]
Expand All @@ -81,6 +80,7 @@ plugin-detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-format
plugin-dokkatoo = { module = "dev.adamko.dokkatoo:dokkatoo-plugin", version.ref = "dokkatooPlugin" }
plugin-graalVmNativeImage = { module = "org.graalvm.buildtools:native-gradle-plugin", version.ref = "graalVmNativeImagePlugin" }
plugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlinPlugin" }
plugin-ksp = { module = "com.google.devtools.ksp:com.google.devtools.ksp.gradle.plugin", version.ref = "ksp" }
plugin-mavenPublish = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "mavenPublishPlugin" }

asciidoctorj = { module = "org.asciidoctor:asciidoctorj", version.ref = "asciidoctorj" }
Expand Down
6 changes: 1 addition & 5 deletions plugins/advisors/nexus-iq/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@

plugins {
// Apply precompiled plugins.
id("ort-library-conventions")

// Apply third-party plugins.
alias(libs.plugins.ksp)
id("ort-plugin-conventions")
}

dependencies {
Expand All @@ -34,5 +31,4 @@ dependencies {
implementation(projects.utils.ortUtils)

ksp(projects.advisor)
ksp(projects.plugins.compiler)
}
6 changes: 1 addition & 5 deletions plugins/advisors/oss-index/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@

plugins {
// Apply precompiled plugins.
id("ort-library-conventions")

// Apply third-party plugins.
alias(libs.plugins.ksp)
id("ort-plugin-conventions")
}

dependencies {
Expand All @@ -34,7 +31,6 @@ dependencies {
implementation(projects.utils.ortUtils)

ksp(projects.advisor)
ksp(projects.plugins.compiler)

testImplementation(libs.wiremock)
}
6 changes: 1 addition & 5 deletions plugins/advisors/osv/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@

plugins {
// Apply precompiled plugins.
id("ort-library-conventions")

// Apply third-party plugins.
alias(libs.plugins.ksp)
id("ort-plugin-conventions")
}

dependencies {
Expand All @@ -38,5 +35,4 @@ dependencies {
implementation(libs.kotlinx.serialization.json)

ksp(projects.advisor)
ksp(projects.plugins.compiler)
}
6 changes: 1 addition & 5 deletions plugins/advisors/vulnerable-code/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@

plugins {
// Apply precompiled plugins.
id("ort-library-conventions")

// Apply third-party plugins.
alias(libs.plugins.ksp)
id("ort-plugin-conventions")
}

dependencies {
Expand All @@ -34,7 +31,6 @@ dependencies {
implementation(projects.utils.ortUtils)

ksp(projects.advisor)
ksp(projects.plugins.compiler)

testImplementation(libs.wiremock)
}
24 changes: 7 additions & 17 deletions plugins/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,37 +113,27 @@ Here, the `serverUrl` property has a default value, the `timeout` property is re

### Gradle Configuration

A Gradle module that contains an ORT plugin implementation must apply the `com.google.devtools.ksp` Gradle plugin:
A Gradle module that contains an ORT plugin implementation must apply the `com.google.devtools.ksp` Gradle plugin and add dependencies to the ORT compiler plugin and the API of the implemented extension point to the KSP configuration:

```kotlin
plugins {
id("com.google.devtools.ksp:[version]")
}
```

Or in the ORT codebase:

```kotlin
plugins {
alias(libs.plugins.ksp)
}
```

It also must add the ORT plugin API and the API of the implemented extension point to the KSP configuration.
For example, an advisor plugin implementation would add the following dependencies:

```kotlin
dependencies {
ksp("org.ossreviewtoolkit:advisor:[version]")
ksp("org.ossreviewtoolkit:plugins-compiler:[version]")
ksp("org.ossreviewtoolkit:compiler:[version]")
}
```

Or in the ORT codebase:
In the ORT codebase, the `ort-plugin-conventions` should be applied so that only a dependency on the extension point API is required:

```kotlin
plugins {
id("ort-plugin-conventions")
}

dependencies {
ksp(projects.advisor)
ksp(projects.plugins.api)
}
```

0 comments on commit b82a5c1

Please sign in to comment.