Skip to content

Commit 124d947

Browse files
committed
jooby-gradle-plugin: Update plugint to work with 6.8 or higher
- jooby-gradle-plugin isn't a maven project anymore - code was updated to work on 6.8 or higher - an error is displayed when running old version - update plugins to use `mainClass` - deprecate `mainClassName` - update cli-generator to use latest gradle 7.x Fixes #2326 #2351
1 parent 970a4f4 commit 124d947

File tree

12 files changed

+162
-147
lines changed

12 files changed

+162
-147
lines changed

etc/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
DIR=$(cd "$(dirname "$0")"; pwd)
44

5-
sh $DIR/maven.sh clean checkstyle:checkstyle -P checkstyle package
5+
sh $DIR/maven.sh clean checkstyle:checkstyle -P checkstyle,gradlePlugin package

etc/release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
DIR=$(cd "$(dirname "$0")"; pwd)
44

5-
sh $DIR/maven.sh -pl '!docs,!tests' clean deploy -P bom,central,publishPlugins
5+
sh $DIR/maven.sh -pl '!docs,!tests' clean deploy -P bom,central,gradlePlugin

modules/jooby-cli/src/main/resources/cli/build.gradle.hbs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ plugins {
1717
id "io.jooby.openAPI" version "${joobyVersion}"
1818
{{/if}}
1919
id "io.jooby.run" version "${joobyVersion}"
20-
id "io.spring.dependency-management" version "1.0.9.RELEASE"
21-
id "com.google.osdetector" version "1.6.2"
22-
id "com.github.johnrengelman.shadow" version "5.2.0"
20+
id "io.spring.dependency-management" version "1.0.11.RELEASE"
21+
id "com.google.osdetector" version "1.7.0"
22+
id "com.github.johnrengelman.shadow" version "7.0.0"
2323
}
2424

2525
group "{{groupId}}"
@@ -30,7 +30,6 @@ sourceCompatibility = 1.8
3030
repositories {
3131
mavenLocal()
3232
mavenCentral()
33-
jcenter()
3433
}
3534

3635
dependencyManagement {

modules/jooby-cli/src/main/resources/cli/gradle/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
33
zipStoreBase=GRADLE_USER_HOME
44
zipStorePath=wrapper/dists
5-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6-bin.zip
5+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip

modules/jooby-gradle-plugin/build.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// First, apply the publishing plugin
22
plugins {
3-
id "com.gradle.plugin-publish" version "0.11.0"
3+
id "maven-publish"
4+
id "com.gradle.plugin-publish" version "0.15.0"
45
id "java-gradle-plugin"
56
}
67

@@ -11,9 +12,11 @@ plugins {
1112
repositories {
1213
mavenLocal()
1314
mavenCentral()
14-
jcenter()
1515
}
1616

17+
def pom = new XmlSlurper().parse(projectDir.toPath().getParent().resolve("pom.xml").toFile())
18+
def joobyVersion = project.properties['joobyVersion'] ?: pom.parent.version
19+
1720
// Unless overridden in the pluginBundle config DSL, the project version will
1821
// be used as your plugin version when publishing
1922
version = "${joobyVersion}"

modules/jooby-gradle-plugin/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
33
zipStoreBase=GRADLE_USER_HOME
44
zipStorePath=wrapper/dists
5-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-bin.zip
5+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip

modules/jooby-gradle-plugin/pom.xml

Lines changed: 0 additions & 110 deletions
This file was deleted.

modules/jooby-gradle-plugin/src/main/java/io/jooby/gradle/BaseTask.java

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@
55
*/
66
package io.jooby.gradle;
77

8-
import org.gradle.api.DefaultTask;
9-
import org.gradle.api.Project;
10-
import org.gradle.api.artifacts.Configuration;
11-
import org.gradle.api.plugins.JavaPluginConvention;
12-
import org.gradle.api.tasks.SourceSet;
13-
14-
import javax.annotation.Nonnull;
158
import java.io.File;
169
import java.net.MalformedURLException;
1710
import java.net.URL;
@@ -22,10 +15,22 @@
2215
import java.util.Collections;
2316
import java.util.LinkedHashSet;
2417
import java.util.List;
18+
import java.util.Objects;
2519
import java.util.Optional;
2620
import java.util.Set;
2721
import java.util.function.Predicate;
2822
import java.util.stream.Collectors;
23+
import java.util.stream.Stream;
24+
25+
import javax.annotation.Nonnull;
26+
27+
import org.gradle.api.DefaultTask;
28+
import org.gradle.api.Project;
29+
import org.gradle.api.artifacts.Configuration;
30+
import org.gradle.api.plugins.JavaApplication;
31+
import org.gradle.api.plugins.JavaPluginConvention;
32+
import org.gradle.api.tasks.Internal;
33+
import org.gradle.api.tasks.SourceSet;
2934

3035
/**
3136
* Base class which provides common utility method to more specific plugins: like classpath
@@ -37,13 +42,14 @@
3742
*/
3843
public class BaseTask extends DefaultTask {
3944

40-
protected static final String APP_CLASS = "mainClassName";
45+
protected static final String APP_CLASS_NAME = "mainClassName";
4146

4247
/**
4348
* Available projects.
4449
*
4550
* @return Available projects.
4651
*/
52+
@Internal
4753
public @Nonnull List<Project> getProjects() {
4854
return Collections.singletonList(getProject());
4955
}
@@ -56,11 +62,22 @@ public class BaseTask extends DefaultTask {
5662
*/
5763
protected @Nonnull String computeMainClassName(@Nonnull List<Project> projects) {
5864
return projects.stream()
59-
.filter(it -> it.getProperties().containsKey(APP_CLASS))
60-
.map(it -> it.getProperties().get(APP_CLASS).toString())
65+
.map(it -> {
66+
// Old way:
67+
String mainClassName = Optional.ofNullable(it.getProperties().get(APP_CLASS_NAME))
68+
.map(Objects::toString)
69+
.orElseGet(() ->
70+
// New way:
71+
Optional.ofNullable(it.getConvention().findByType(JavaApplication.class))
72+
.map(plugin -> plugin.getMainClass().getOrNull())
73+
.orElse(null)
74+
);
75+
return mainClassName;
76+
})
77+
.filter(Objects::nonNull)
6178
.findFirst()
6279
.orElseThrow(() -> new IllegalArgumentException(
63-
"Application class not found. Did you forget to set `" + APP_CLASS + "`?"));
80+
"Application class not found. Did you forget to set `" + APP_CLASS_NAME + "`?"));
6481
}
6582

6683
/**
@@ -135,7 +152,8 @@ public class BaseTask extends DefaultTask {
135152
* @param sourceSet Source set.
136153
* @return Source directories.
137154
*/
138-
protected @Nonnull Set<Path> sourceDirectories(@Nonnull Project project, @Nonnull SourceSet sourceSet) {
155+
protected @Nonnull Set<Path> sourceDirectories(@Nonnull Project project,
156+
@Nonnull SourceSet sourceSet) {
139157
Path eclipse = project.getProjectDir().toPath().resolve(".classpath");
140158
if (Files.exists(eclipse)) {
141159
// let eclipse to do the incremental compilation

modules/jooby-gradle-plugin/src/main/java/io/jooby/gradle/OpenAPITask.java

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import io.jooby.openapi.OpenAPIGenerator;
99
import io.swagger.v3.oas.models.OpenAPI;
1010
import org.gradle.api.Project;
11+
import org.gradle.api.model.ReplacedBy;
12+
import org.gradle.api.tasks.Input;
1113
import org.gradle.api.tasks.TaskAction;
1214

1315
import javax.annotation.Nonnull;
@@ -26,7 +28,7 @@
2628
*/
2729
public class OpenAPITask extends BaseTask {
2830

29-
private String mainClassName;
31+
private String mainClass;
3032

3133
private String includes;
3234

@@ -41,14 +43,14 @@ public class OpenAPITask extends BaseTask {
4143
public void generate() throws Throwable {
4244
List<Project> projects = getProjects();
4345

44-
String mainClass = Optional.ofNullable(mainClassName)
46+
String mainClass = Optional.ofNullable(this.mainClass)
4547
.orElseGet(() -> computeMainClassName(projects));
4648

4749
Path outputDir = classes(getProject());
4850

4951
ClassLoader classLoader = createClassLoader(projects);
5052

51-
getLogger().info(" Generating OpenAPI: " + mainClass);
53+
getLogger().info("Generating OpenAPI: " + mainClass);
5254
getLogger().debug("Using classloader: " + classLoader);
5355
getLogger().debug("Output directory: " + outputDir);
5456

@@ -71,23 +73,47 @@ public void generate() throws Throwable {
7173
*
7274
* @return Class to parse.
7375
*/
74-
public @Nonnull String getMainClassName() {
75-
return mainClassName;
76+
@Input
77+
@org.gradle.api.tasks.Optional
78+
public String getMainClass() {
79+
return mainClass;
7680
}
7781

7882
/**
7983
* Set Class to parse.
8084
* @param mainClassName Class to parse.
8185
*/
82-
public void setMainClassName(@Nonnull String mainClassName) {
83-
this.mainClassName = mainClassName;
86+
public void setMainClass(String mainClassName) {
87+
this.mainClass = mainClassName;
88+
}
89+
90+
/**
91+
* Class to parse.
92+
*
93+
* @return Class to parse.
94+
*/
95+
@Deprecated
96+
@ReplacedBy("mainClass")
97+
public String getMainClassName() {
98+
return getMainClass();
99+
}
100+
101+
/**
102+
* Set Class to parse.
103+
* @param mainClassName Class to parse.
104+
*/
105+
@Deprecated
106+
public void setMainClassName(String mainClassName) {
107+
setMainClass(mainClassName);
84108
}
85109

86110
/**
87111
* Regular expression used to includes/keep route. Example: <code>/api/.*</code>.
88112
*
89113
* @return Regular expression used to includes/keep route. Example: <code>/api/.*</code>.
90114
*/
115+
@Input
116+
@org.gradle.api.tasks.Optional
91117
public @Nullable String getIncludes() {
92118
return includes;
93119
}
@@ -106,6 +132,8 @@ public void setIncludes(@Nullable String includes) {
106132
*
107133
* @return Regular expression used to excludes route. Example: <code>/web</code>.
108134
*/
135+
@Input
136+
@org.gradle.api.tasks.Optional
109137
public @Nullable String getExcludes() {
110138
return excludes;
111139
}

0 commit comments

Comments
 (0)