Skip to content

Commit 5cbc086

Browse files
committed
update documentation
1 parent 8b06f45 commit 5cbc086

1 file changed

Lines changed: 82 additions & 40 deletions

File tree

docs/modules/ROOT/pages/index.adoc

Lines changed: 82 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ Apart from that there are only two options that are recognized inside the config
5757
processors and placing it directly into the `openapiProcessor` block sets it for all processors.
5858

5959
* `checkUpdates`, which allows to enable a version check for the Gradle plugin itself and any processor that supports a version check. It can have one of 3 values:
60-
+
61-
* `never`, this is the default and disables all update checks.
62-
* `daily`, this will check once a day if there is a newer version available. The plugin remembers the last check by writing a timestamp to `build/openapiprocessor/<processor>.yaml`. Without that file the check will run, e.g. after a clean checkout or after running the `clean` task.
63-
* `always`, this will check on any run of Gradle or a processor task if a newer version is available.
60+
61+
** `never`, this is the default and disables all update checks.
62+
** `daily`, this will check once a day if there is a newer version available. The plugin remembers the last check by writing a timestamp to `build/openapiprocessor/<processor>.yaml`. Without that file the check will run, e.g. after a clean checkout or after running the `clean` task.
63+
** `always`, this will check on any run of Gradle or a processor task if a newer version is available.
6464

6565
To configure a processor, for example xref:spring:ROOT:index.adoc[openapi-processor-spring], place a `spring` configuration into the `openapiProcessor` block. The name of the configuration is used to create a Gradle task `process<Name>` to run the corresponding processor.
6666

@@ -76,6 +76,9 @@ openapiProcessor {
7676
7777
// the path to the open api YAML file.
7878
apiPath("${projectDir}/src/api/openapi.yaml")
79+
// alternatives, since 2025.1
80+
// apiPath(file("$projectDir/src/api/openapi.yaml"))
81+
// apiPath(layout.projectDirectory.file("src/api/openapi.yaml"))
7982
8083
process("spring") {
8184
// ... options of openapi-processor-spring
@@ -93,6 +96,9 @@ openapiProcessor {
9396
9497
// the path to the open api YAML file.
9598
apiPath "${projectDir}/src/api/openapi.yaml"
99+
// alternatives, since 2025.1
100+
//apiPath file("$projectDir/src/api/openapi.yaml")
101+
//apiPath layout.projectDirectory.file("src/api/openapi.yaml")
96102
97103
spring {
98104
// ... options of openapi-processor-spring
@@ -118,8 +124,8 @@ openapiProcessor {
118124
// the path to the open api YAML file.
119125
apiPath("${projectDir}/src/api/openapi.yaml")
120126
// alternatives, since 2025.1
121-
apiPath(file("$projectDir/src/api/openapi.yaml"))
122-
apiPath(layout.projectDirectory.file("src/api/openapi.yaml"))
127+
// apiPath(file("$projectDir/src/api/openapi.yaml"))
128+
// apiPath(layout.projectDirectory.file("src/api/openapi.yaml"))
123129
124130
process("spring") {
125131
// ... options of openapi-processor-spring
@@ -141,6 +147,9 @@ openapiProcessor {
141147
142148
// the path to the open api YAML file.
143149
apiPath "${projectDir}/src/api/openapi.yaml"
150+
// alternatives, since 2025.1
151+
// apiPath file("$projectDir/src/api/openapi.yaml")
152+
// apiPath layout.projectDirectory.file("src/api/openapi.yaml")
144153
145154
spring {
146155
// ... options of openapi-processor-spring
@@ -207,7 +216,14 @@ spring {
207216
+
208217
It is possible to use multiple `processor` entries to control the dependencies of an openapi-processor.
209218
+
210-
For example, the java generating processors depend on `openapi-processor-core`. The `core` library provides most of the logic of a processor, and it is usually enough to update the `core` library to get bugfixes or new features. To find 'SNAPSHOT' versions the plugin automatically adds the snapshot repository to the `repositories`. ([.badge .badge-since]+since 2022.2+, In case you don't want this it is possible to disable adding the snapshot repository by adding `openapi-processor-gradle.snapshots = false` to `gradle.properties`).
219+
For example, the java generating processors depend on `openapi-processor-core`. The `core` library provides most of the logic of a processor, and it is usually enough to update the `core` library to get bugfixes or new features.
220+
+
221+
[NOTE]
222+
====
223+
To find 'SNAPSHOT' versions the plugin automatically adds the snapshot repository to the `repositories`.
224+
225+
[.badge .badge-since]+since 2022.2+ In case you don't want this it is possible to disable adding the snapshot repository by adding `openapi-processor-gradle.snapshots = false` to `gradle.properties`).
226+
====
211227
+
212228
[tabs]
213229
====
@@ -265,12 +281,17 @@ The plugin does not add the `process<Name>` task to the build lifecycle.
265281
To automatically run it
266282

267283
* add a task dependency in the `build.gradle` file
268-
* or use the task output when configuring the additional `SourceSet` directories (see xref:_using_the_processor_output[])
284+
* or use the task output when configuring the additional `SourceSet` directories (see xref:_using_the_task_output[])
269285

270286
The second way is the newer and preferred way.
271287

272288
=== `dependOn` a processing task
273289

290+
[NOTE]
291+
====
292+
This will continue to work but xref:_using_the_task_output[] is the better and preferred configuration.
293+
====
294+
274295
To automatically run a processing task, e.g. `processSpring`, it is necessary to create a dependency on the task.
275296

276297
Here is a simple example:
@@ -304,7 +325,7 @@ compileJava.dependsOn ('processSpring')
304325

305326
==== using the task name
306327

307-
The Gradle plugin creates the processing tasks inside an `afterEvaluate` block (because its name is configurable). To directly use its name, like in the example below, teh configuration needs to be in an `afterEvaluate` block.
328+
The Gradle plugin creates the processing tasks inside an `afterEvaluate` block (because its name is configurable). To directly use its name, like in the example below, the configuration needs to be in an `afterEvaluate` block.
308329

309330
[source,groovy]
310331
----
@@ -320,24 +341,25 @@ afterEvaluate {
320341
}
321342
----
322343

323-
[#_using_the_processor_output]
324-
== using the processor output
344+
[#_using_the_task_output]
345+
== using the task output
325346

326347
In case the processor creates java sources it is necessary to compile them as part of the build process.
327348

328349
To compile the java source files created by openapi-processor-spring add the `targetDir` of the processor to the java `sourceSets`.
329350

330351
There are two ways to configure it:
331352

332-
* using a path string, which requires a `dependsOn` configuration
333-
* or using the task output, which does not need `dependsOn`
353+
* using a path string which will need the `dependsOn` configuration to trigger the processor before compilation
354+
* or using the task output, which will avoid the need for `dependsOn`. Gradle will automatically detect that it has to run the processor first.
334355

335356
=== by path string
336357

337358
Using a path string it is simply added as an additional `srcDir`:
338359

339360
[tabs]
340361
====
362+
341363
Kotlin::
342364
+
343365
[source,kotlin]
@@ -348,6 +370,7 @@ sourceSets {
348370
java {
349371
// add generated files
350372
srcDir("build/openapi")
373+
//srcDir(layout.buildDirectory.dir("openapi"))
351374
}
352375
}
353376
}
@@ -362,6 +385,7 @@ sourceSets {
362385
java {
363386
// add generated files
364387
srcDir 'build/openapi'
388+
//srcDir layout.buildDirectory.dir("openapi")
365389
}
366390
}
367391
}
@@ -402,6 +426,8 @@ sourceSets {
402426

403427
=== by task output
404428

429+
[.badge .badge-since]+since 2025.1+
430+
405431
A preferred approach to avoid `dependsOn` and to support lazy configuration is to use the task output to configure the additional `SourceSet` directories.
406432

407433
[tabs]
@@ -412,15 +438,24 @@ Kotlin::
412438
----
413439
import io.openapiprocessor.gradle.OpenApiProcessorTask
414440
415-
afterEvaluate {
416-
sourceSets {
417-
create("api") {
418-
resources {
419-
// add api resources
420-
srcDir("${projectDir}/src/api")
441+
sourceSets {
442+
create("api") {
443+
resources {
444+
// add api resources
445+
srcDir("${projectDir}/src/api")
446+
}
447+
}
448+
449+
afterEvaluate {
450+
// if the processor generates java files only, directly to targetDir
451+
main {
452+
java {
453+
// add generated files
454+
srcDir(tasks.named("processSpring"))
421455
}
422456
}
423457
458+
// if the processor generates java and resource files to the targetDir it is necessary to select the subfolder
424459
main {
425460
java {
426461
// add generated files
@@ -521,7 +556,7 @@ This is possible by configuring the repositories checked for plugins using a `pl
521556
// build.gradle
522557
523558
plugins {
524-
id 'io.openapiprocessor.openapi-processor" version "2022.2-SNAPSHOT'
559+
id 'io.openapiprocessor.openapi-processor" version "2025.6-SNAPSHOT'
525560
}
526561
527562
@@ -530,7 +565,7 @@ plugins {
530565
pluginManagement {
531566
repositories {
532567
maven {
533-
url 'https://oss.sonatype.org/content/repositories/snapshots'
568+
url 'https://central.sonatype.com/repository/maven-snapshots'
534569
}
535570
gradlePluginPortal()
536571
}
@@ -555,7 +590,8 @@ openapiProcessor {
555590
556591
// the path to the open api YAML file. Usually the same for all processors.
557592
//
558-
apiPath("${projectDir}/src/api/openapi.yaml")
593+
//apiPath("${projectDir}/src/api/openapi.yaml")
594+
apiPath(layout.projectDirectory.file("src/api/openapi.yaml"))
559595
560596
// based on the name of a processor configuration the plugin creates a Gradle task with name
561597
// "process${name of processor}" (in this case "processSpring") to run the processor.
@@ -572,7 +608,8 @@ openapiProcessor {
572608
// the destination folder for generating interfaces & models. This is the parent of the
573609
// {package-name} folder tree configured in the mapping file. (mandatory)
574610
//
575-
targetDir("${projectDir}/build/openapi")
611+
//targetDir("${projectDir}/build/openapi")
612+
targetDir(layout.buildDirectory.dir("openapi"))
576613
577614
//// openapi-processor-spring specific options
578615
//// in a kotlin build script it is necessary to use the prop(key, value) or prop(map)
@@ -581,7 +618,8 @@ openapiProcessor {
581618
// file name of the mapping YAML configuration file. Note that the YAML file name must end
582619
// with either {@code .yaml} or {@code .yml}.
583620
//
584-
prop("mapping", "${projectDir}/src/api/mapping.yaml")
621+
//prop("mapping", "${projectDir}/src/api/mapping.yaml")
622+
prop("mapping", layout.projectDirectory.file("src/api/mapping.yaml"))
585623
}
586624
587625
// applying the rule described above the task to run this one is "processJson".
@@ -592,9 +630,9 @@ openapiProcessor {
592630
processor("'io.openapiprocessor:openapi-processor-json:<version>")
593631
594632
// the destination folder for the JSON file. (mandatory)
595-
targetDir("${buildDir}/json")
633+
//targetDir("${buildDir}/json")
634+
targetDir(layout.buildDirectory.dir("json"))
596635
}
597-
598636
}
599637
----
600638
Groovy::
@@ -607,7 +645,8 @@ openapiProcessor {
607645
608646
// the path to the open api yaml file. Usually the same for all processors.
609647
//
610-
apiPath "${projectDir}/src/api/openapi.yaml"
648+
// apiPath "${projectDir}/src/api/openapi.yaml"
649+
apiPath layout.projectDirectory.file("src/api/openapi.yaml")
611650
612651
// based on the name of a processor configuration the plugin creates a gradle task with name
613652
// "process${name of processor}" (in this case "processSpring") to run the processor.
@@ -624,14 +663,16 @@ openapiProcessor {
624663
// the destination folder for generating interfaces & models. This is the parent of the
625664
// {package-name} folder tree configured in the mapping file. (mandatory)
626665
//
627-
targetDir "${projectDir}/build/openapi"
666+
//targetDir "${projectDir}/build/openapi"
667+
targetDir layout.buildDirectory.dir("openapi")
628668
629669
//// openapi-processor-spring specific options
630670
631671
// file name of the mapping yaml configuration file. Note that the yaml file name must end
632672
// with either {@code .yaml} or {@code .yml}.
633673
//
634-
mapping "${projectDir}/src/api/mapping.yaml"
674+
//mapping "${projectDir}/src/api/mapping.yaml"
675+
mapping layout.projectDirectory.file("src/api/mapping.yaml")
635676
}
636677
637678
// applying the rule described above the task to run this one is "processJson".
@@ -642,7 +683,8 @@ openapiProcessor {
642683
processor 'io.openapiprocessor:openapi-processor-json:<version>'
643684
644685
// the destination folder for the json file. (mandatory)
645-
targetDir "${buildDir}/json"
686+
//targetDir "${buildDir}/json"
687+
targetDir layout.buildDirectory.dir("json")
646688
}
647689
648690
}
@@ -661,17 +703,17 @@ Kotlin::
661703
// build.gradle.kts
662704
663705
openapiProcessor {
664-
apiPath("${projectDir}/src/api/openapi.yaml")
706+
apiPath(layout.projectDirectory.file("src/api/openapi.yaml"))
665707
666708
process("spring") {
667709
processor("io.openapiprocessor:openapi-processor-spring:<version>")
668-
targetDir("${projectDir}/build/openapi")
669-
prop("mapping", "${projectDir}/src/api/mapping.yaml")
710+
targetDir(layout.buildDirectory.dir("openapi"))
711+
prop("mapping", layout.projectDirectory.file("src/api/mapping.yaml"))
670712
}
671713
672714
process("json") {
673715
processor("io.openapiprocessor:openapi-processor-json:<version>")
674-
targetDir("${buildDir}/json")
716+
targetDir(layout.buildDirectory.dir("json"))
675717
}
676718
}
677719
----
@@ -682,17 +724,17 @@ Groovy::
682724
// build.gradle
683725
684726
openapiProcessor {
685-
apiPath "${projectDir}/src/api/openapi.yaml"
727+
apiPath layout.projectDirectory.file("src/api/openapi.yaml")
686728
687729
spring {
688-
processor 'io.openapiprocessor:openapi-processor-spring:<version>'
689-
targetDir "${projectDir}/build/openapi"
690-
mapping "${projectDir}/src/api/mapping.yaml"
730+
processor "io.openapiprocessor:openapi-processor-spring:<version>"
731+
targetDir layout.buildDirectory.dir("openapi")
732+
mapping layout.projectDirectory.file("src/api/mapping.yaml")
691733
}
692734
693735
json {
694-
processor 'io.openapiprocessor:openapi-processor-json:<version>'
695-
targetDir "${buildDir}/json"
736+
processor "io.openapiprocessor:openapi-processor-json:<version>"
737+
targetDir layout.buildDirectory.dir("json")
696738
}
697739
}
698740
----

0 commit comments

Comments
 (0)