-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc(crd-generator): add usage description for Gradle users (6722)
Signed-off-by: Bernhard Strähle <[email protected]>
- Loading branch information
Showing
3 changed files
with
119 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# CRD Generator | ||
|
||
## Modules | ||
|
||
### CRD Generator v1 (deprecated since 7.0.0) | ||
|
||
- **CRD Generator API v1** - `io.fabric8:crd-generator-api` | ||
_Core implementation of the old generator, based on [sundrio](https://github.com/sundrio/sundrio)._ | ||
- **CRD Generator annotation processing tool (APT)** - `io.fabric8:crd-generator-apt` | ||
_Annotation processor which hooks into the build process to generate CRDs._ | ||
|
||
### CRD Generator v2 | ||
- **CRD Generator API v2** - `io.fabric8:crd-generator-api-v2` | ||
_Core implementation of the new generator, based on [Jackson/jsonSchema](https://github.com/FasterXML/jackson-module-jsonSchema)._ | ||
- **CRD Generator Collector** - `io.fabric8:crd-generator-collector` | ||
_Shared component to find and load compiled Custom Resource classes in directories and Jar files._ | ||
- **CRD Generator Maven Plugin** - `io.fabric8:crd-generator-maven-plugin` | ||
_Maven plugin that generates CRDs during the build process._ | ||
- **CRD Generator CLI** - `io.fabric8:crd-generator-cli` | ||
_CLI tool that generates CRDs when executed._ | ||
|
||
### Utility Modules | ||
_(not published)_ | ||
|
||
- **test-apt** - `io.fabric8:crd-generator-test-apt` | ||
_Integration tests for CRD Generator API v1 and the annotation processor tool_ | ||
- **test** - `io.fabric8:crd-generator-test` | ||
_Approval tests for CRD Generator API v1 and v2_ | ||
|
||
## Usage | ||
|
||
- [Introduction and Annotation usage](../doc/CRD-generator.md) | ||
- [CRD Generator Maven Plugin](maven-plugin/README.md) | ||
- [CRD Generator CLI tool](cli/README.md) | ||
- [CRD Generator usage with Gradle in build script](gradle/README.md) | ||
|
||
### Deprecated Tools | ||
|
||
- [CRD Generator annotation processing tool (APT)](apt/README.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# CRD Generator - Usage with Gradle in build script | ||
|
||
The CRD Generator v2 can be used in a [build script](https://docs.gradle.org/current/userguide/writing_build_scripts.html) without an additional plugin: | ||
|
||
## Kotlin DSL (`build.gradle.kts`) | ||
|
||
```kotlin | ||
import io.fabric8.crdv2.generator.CRDGenerationInfo | ||
import io.fabric8.crdv2.generator.CRDGenerator | ||
import io.fabric8.crd.generator.collector.CustomResourceCollector | ||
import java.nio.file.Files | ||
|
||
plugins { | ||
id("java") | ||
} | ||
|
||
group = "io.fabric8.crd-generator.gradle" | ||
version = "0.0.1-SNAPSHOT" | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
compileOnly("io.fabric8:kubernetes-client-api:7.0.0") | ||
} | ||
|
||
buildscript { | ||
repositories { | ||
mavenCentral() | ||
} | ||
dependencies { | ||
classpath("io.fabric8:crd-generator-api-v2:7.0.0") | ||
classpath("io.fabric8:crd-generator-collector:7.0.0") | ||
} | ||
} | ||
|
||
tasks.register("generateCrds") { | ||
description = "Generate CRDs from compiled custom resource classes" | ||
group = "crd" | ||
|
||
val sourceSet = project.sourceSets["main"] | ||
|
||
val compileClasspathElements = sourceSet.compileClasspath.map { e -> e.absolutePath } | ||
|
||
val outputClassesDirs = sourceSet.output.classesDirs | ||
val outputClasspathElements = outputClassesDirs.map { d -> d.absolutePath } | ||
|
||
val classpathElements = listOf(outputClasspathElements, compileClasspathElements).flatten() | ||
val filesToScan = listOf(outputClassesDirs).flatten() | ||
val outputDir = sourceSet.output.resourcesDir | ||
|
||
doLast { | ||
Files.createDirectories(outputDir!!.toPath()) | ||
|
||
val collector = CustomResourceCollector() | ||
.withParentClassLoader(Thread.currentThread().contextClassLoader) | ||
.withClasspathElements(classpathElements) | ||
.withFilesToScan(filesToScan) | ||
|
||
val crdGenerator = CRDGenerator() | ||
.customResourceClasses(collector.findCustomResourceClasses()) | ||
.inOutputDir(outputDir) | ||
|
||
val crdGenerationInfo: CRDGenerationInfo = crdGenerator.detailedGenerate() | ||
|
||
crdGenerationInfo.crdDetailsPerNameAndVersion.forEach { (crdName, versionToInfo) -> | ||
println("Generated CRD $crdName:") | ||
versionToInfo.forEach { (version, info) -> println(" $version -> ${info.filePath}") } | ||
} | ||
} | ||
} | ||
|
||
tasks.named(JvmConstants.CLASSES_TASK_NAME) { | ||
finalizedBy("generateCrds") | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters