Skip to content

Commit

Permalink
[gradle] Enabling up-to-date checks and gradle caching for openapigen…
Browse files Browse the repository at this point in the history
…erator tasks (#6716)
  • Loading branch information
HenningWaack authored Aug 10, 2020
1 parent 6f0bef6 commit e4c858c
Show file tree
Hide file tree
Showing 10 changed files with 250 additions and 101 deletions.
6 changes: 3 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ install:
# install gradle
- ps: |
Add-Type -AssemblyName System.IO.Compression.FileSystem
if (!(Test-Path -Path "C:\gradle" )) {
if (!(Test-Path -Path "C:\gradle\gradle-5.6.4" )) {
(new-object System.Net.WebClient).DownloadFile(
'https://services.gradle.org/distributions/gradle-5.3.1-bin.zip',
'https://services.gradle.org/distributions/gradle-5.6.4-bin.zip',
'C:\gradle-bin.zip'
)
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\gradle-bin.zip", "C:\gradle")
}
- cmd: SET PATH=C:\maven\apache-maven-3.2.5\bin;C:\gradle\gradle-5.3.1\bin;%JAVA_HOME%\bin;%PATH%
- cmd: SET PATH=C:\maven\apache-maven-3.2.5\bin;C:\gradle\gradle-5.6.4\bin;%JAVA_HOME%\bin;%PATH%
- cmd: SET MAVEN_OPTS=-Xmx4g
- cmd: SET JAVA_OPTS=-Xmx4g
- cmd: SET M2_HOME=C:\maven\apache-maven-3.2.5
Expand Down
29 changes: 29 additions & 0 deletions modules/openapi-generator-gradle-plugin/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,35 @@ task validateBadSpec(type: org.openapitools.generator.gradle.plugin.tasks.Valida
task validateSpecs(dependsOn: ['validateGoodSpec', 'validateBadSpec'])
----

[NOTE]
====
The tasks support Gradle Up-To-Date checking and Gradle Cache. Enable caching globally by setting `org.gradle.caching=true` in the `gradle.settings`
file or by passing the command line property `--build-cache` when executing on the command line.
Disable up-to-date checks and caching by setting the following property when using the extension:
.Disable caching for extension
[source,groovy]
----
tasks.withType(org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
outputs.upToDateWhen { false }
outputs.cacheIf { false }
}
----
Disable up-to-date checks and caching for a custom task:
.Disable caching for custom task
[source,groovy]
----
task validateGoodSpec(type: org.openapitools.generator.gradle.plugin.tasks.ValidateTask){
outputs.upToDateWhen { false }
outputs.cacheIf { false }
inputSpec = "$rootDir/petstore-v3.0.yaml".toString()
}
----
====

== Plugin Setup

//# RELEASE_VERSION
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Thu Jan 30 22:14:34 EST 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Local Spec Sample

This example assumes you have Gradle 4.7+ installed. No gradle wrapper is provided in samples.
This example assumes you have Gradle 5.6.4+ installed. No gradle wrapper is provided in samples.

First, publish the openapi-generator-gradle-plugin locally via `./gradlew assemble install` in the module directory.
First, publish the openapi-generator-gradle-plugin locally via `./gradlew assemble publishToMavenLocal` in the module directory.

Then, run the following tasks in this example directory.

```bash
gradle openApiGenerate
gradle openApiMeta
gradle openApiValidate
gradle buildGoSdk
gradle buildDotnetSdk
gradle generateGoWithInvalidSpec
gradle openApiGenerate # expected outcome: BUILD SCCESSFUL
gradle openApiMeta # expected outcome: BUILD SCCESSFUL
gradle openApiValidate # expected outcome: BUILD FAILED
gradle buildGoSdk # expected outcome: BUILD SCCESSFUL
gradle buildDotnetSdk # expected outcome: BUILD SCCESSFUL
gradle generateGoWithInvalidSpec # expected outcome: BUILD FAILED
```

The samples can be tested against other versions of the plugin using the `openApiGeneratorVersion` property. For example:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ class OpenApiGeneratorPlugin : Plugin<Project> {
)

val generators = extensions.create(
"openApiGenerators",
OpenApiGeneratorGeneratorsExtension::class.java,
project
"openApiGenerators",
OpenApiGeneratorGeneratorsExtension::class.java,
project
)

generate.outputDir.set("$buildDir/generate-resources/main")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
}

@Suppress("MemberVisibilityCanBePrivate")
fun applyDefaults(){
fun applyDefaults() {
releaseNote.set("Minor update")
modelNamePrefix.set("")
modelNameSuffix.set("")
Expand Down
Loading

0 comments on commit e4c858c

Please sign in to comment.