Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the kotlin-dsl plugin #112

Merged
merged 5 commits into from
Feb 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Once you setup the plugin correctly, you can call the `:generateSwagger` gradle

In order to run this gradle plugin you need to fulfill the following requirements:

* Gradle 5.x - This plugin uses Gradle 5 features, and you will need to setup your Gradle wrapper to use 5.0 or more.
* Gradle 5.x - This plugin uses Gradle 5 features, and you will need to setup your Gradle wrapper to use 5.4.1 or more.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I bumped from 5.0 to 5.4.1 because the testProject fails on 5.0 due to:

Build file '/home/martin/git/swagger-gradle-codegen/gradle-plugin/plugin/junit7355662627637669365/project/build.gradle.kts' line: 9

* What went wrong:
Script compilation errors:

  Line 09:       content {
                 ^ Unresolved reference: content

  Line 10:         excludeGroup("com.yelp.codegen")
                   ^ Unresolved reference: excludeGroup

I think it should be safe to assume most people are using gradle >= 5.4.1 but we can certainly remove that limitation if really needed.

* Java 8+

## Supported platforms
Expand Down
10 changes: 9 additions & 1 deletion gradle-plugin/plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version = rootProject.version

plugins {
java
`kotlin-dsl`
id("java-gradle-plugin")
`maven-publish`
jacoco
kotlin("jvm") version "1.3.61"
Expand Down Expand Up @@ -38,6 +38,14 @@ tasks.register<Jar>("sourcesJar") {
from(sourceSets.main.get().allJava)
classifier = "sources"
}
gradlePlugin {
plugins {
create("com.yelp.codegen.plugin") {
id = "com.yelp.codegen.plugin"
implementationClass = "com.yelp.codegen.plugin.CodegenPlugin"
}
}
}

// Configuration Block for the Plugin Marker artifact on Plugin Central
pluginBundle {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.yelp.codegen.plugin

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.util.GradleVersion

class CodegenPlugin : Plugin<Project> {
override fun apply(project: Project) {
require(GradleVersion.current() >= GradleVersion.version("5.4.1")) {
"com.yelp.codegen.plugin requires Gradle version 5.4.1 or greater"
}

val config = project.extensions.create("generateSwagger", GenerateTaskConfiguration::class.java, project)

project.tasks.register("generateSwagger", GenerateTask::class.java) {
it.platform = config.platform
it.packageName = config.packageName
it.specName = config.specName
it.specVersion = config.specVersion
it.inputFile = config.inputFile
it.outputDir = config.outputDir

it.extraFiles = config.extraFiles
it.features = config.features
}
}
}

This file was deleted.

16 changes: 16 additions & 0 deletions gradle-plugin/plugin/src/test/java/com/yelp/plugin/PluginTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,20 @@ class PluginTests {
.build()
Assert.assertEquals(TaskOutcome.UP_TO_DATE, result2ndRun.task(":generateSwagger")?.outcome)
}

@Test
fun testMinSupportdGradleVersion() {
val projectDir = temporaryFolder.newFolder("project")
File("src/test/testProject").copyRecursively(projectDir)

val result = GradleRunner.create()
.withProjectDir(projectDir)
.withGradleVersion("5.4.1")
.forwardStdOutput(System.out.writer())
.forwardStdError(System.err.writer())
.withArguments("generateSwagger")
.build()

Assert.assertEquals(TaskOutcome.SUCCESS, result.task(":generateSwagger")?.outcome)
}
}