Skip to content

Commit f78097d

Browse files
authored
Merge pull request #14757 from apache/grails-gradle-plugin-groovy
2 parents d8c31d0 + 8d09d3a commit f78097d

File tree

8 files changed

+287
-10
lines changed

8 files changed

+287
-10
lines changed

.github/workflows/gradle.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ jobs:
9191
develocity-access-key: ${{ secrets.GRAILS_DEVELOCITY_ACCESS_KEY }}
9292
- name: "🔨 Build project"
9393
run: >
94-
./gradlew build :grails-shell-cli:installDist groovydoc
94+
./gradlew :grails-bom:publishMavenPublicationToLocalBomRepository build :grails-shell-cli:installDist groovydoc
9595
--continue --stacktrace -PonlyCoreTests
9696
functional:
9797
name: "Functional Tests"
@@ -117,7 +117,7 @@ jobs:
117117
develocity-access-key: ${{ secrets.GRAILS_DEVELOCITY_ACCESS_KEY }}
118118
- name: "🏃 Run Functional Tests"
119119
run: >
120-
./gradlew bootJar check
120+
./gradlew :grails-bom:publishMavenPublicationToLocalBomRepository bootJar check
121121
--continue --stacktrace
122122
-PonlyFunctionalTests
123123
-PskipHibernate5Tests
@@ -149,7 +149,7 @@ jobs:
149149
env:
150150
GITHUB_MAVEN_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
151151
run: >
152-
./gradlew bootJar cleanTest check
152+
./gradlew :grails-bom:publishMavenPublicationToLocalBomRepository bootJar cleanTest check
153153
--continue --stacktrace
154154
-PonlyMongodbTests
155155
-PmongodbContainerVersion=${{ matrix.mongodb-version }}
@@ -179,7 +179,7 @@ jobs:
179179
env:
180180
GITHUB_MAVEN_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
181181
run: >
182-
./gradlew bootJar cleanTest check
182+
./gradlew :grails-bom:publishMavenPublicationToLocalBomRepository bootJar cleanTest check
183183
--continue --stacktrace
184184
-PonlyHibernate5Tests
185185
publishGradle:

grails-gradle/gradle/e2eTest.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ e2eTestTask.configure { Test it ->
4444
}
4545
it.beforeTest { descriptor -> logger.quiet ' -- $descriptor' }
4646

47-
it.dependsOn 'publishAllPublicationsToTestCaseMavenRepoRepository', ':grails-gradle-bom:publishAllPublicationsToTestCaseMavenRepoRepository'
47+
it.dependsOn 'publishAllPublicationsToTestCaseMavenRepoRepository', ':grails-gradle-tasks:publishAllPublicationsToTestCaseMavenRepoRepository', ':grails-gradle-bom:publishAllPublicationsToTestCaseMavenRepoRepository'
4848
}
4949

5050
tasks.named('check').configure {

grails-gradle/plugins/build.gradle

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ dependencies {
3232
// compile grails-gradle-plugin with the Groovy version provided by Gradle
3333
// to ensure build compatibility with Gradle, currently Groovy 3.0.x
3434
// see: https://docs.gradle.org/current/userguide/compatibility.html#groovy
35-
// TODO: tasks are isolated as of Gradle 7 so we must expose the version of the groovy.
36-
// We could upgrade to groovy 4 for the tasks, but gradle plugins are not isolated and still
37-
// need groovy 3.
38-
implementation "org.codehaus.groovy:groovy"
35+
compileOnly "org.codehaus.groovy:groovy"
36+
37+
implementation project(':grails-gradle-tasks')
3938

4039
implementation project(':grails-gradle-model'), {
4140
exclude group: 'org.apache.groovy'

grails-gradle/settings.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,7 @@ include 'grails-gradle-model'
5555
project(':grails-gradle-model').projectDir = file('model')
5656

5757
include 'grails-docs-core'
58-
project(':grails-docs-core').projectDir = file('docs-core')
58+
project(':grails-docs-core').projectDir = file('docs-core')
59+
60+
include 'grails-gradle-tasks'
61+
project(':grails-gradle-tasks').projectDir = file('tasks')

grails-gradle/tasks/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!--
2+
SPDX-License-Identifier: Apache-2.0
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
https://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
17+
Grails Gradle Task exists due to newer versions of Gradle isolating classpaths of Gradle tasks.

grails-gradle/tasks/build.gradle

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
plugins {
21+
id 'groovy'
22+
id 'java-gradle-plugin'
23+
id 'maven-publish'
24+
}
25+
26+
version = projectVersion
27+
group = 'org.apache.grails'
28+
29+
dependencies {
30+
implementation platform(project(':grails-gradle-bom'))
31+
32+
implementation "org.codehaus.groovy:groovy"
33+
34+
implementation project(':grails-gradle-model'), {
35+
exclude group: 'org.apache.groovy'
36+
exclude group: 'org.spockframework'
37+
}
38+
39+
implementation 'io.github.gradle-nexus:publish-plugin'
40+
implementation 'org.springframework.boot:spring-boot-gradle-plugin'
41+
}
42+
43+
publishing {
44+
if (!isReleaseVersion) {
45+
repositories {
46+
maven {
47+
credentials {
48+
username = System.getenv('MAVEN_PUBLISH_USERNAME')
49+
password = System.getenv('MAVEN_PUBLISH_PASSWORD')
50+
}
51+
url = System.getenv('MAVEN_PUBLISH_URL') ?: 'https://repository.apache.org/content/repositories/snapshots'
52+
}
53+
}
54+
}
55+
56+
// used for e2e testing
57+
// publishAllPublicationsToTestCaseMavenRepoRepository
58+
repositories {
59+
maven {
60+
name = 'TestCaseMavenRepo'
61+
url = rootProject.layout.buildDirectory.dir('local-maven')
62+
}
63+
}
64+
65+
publications {
66+
pluginMaven(MavenPublication) {
67+
pom {
68+
name = 'Grails Gradle Tasks'
69+
description = 'A Gradle tasks for Grails gradle plugins'
70+
71+
url = 'https://github.com/apache/grails-core'
72+
73+
licenses {
74+
license {
75+
name = 'The Apache Software License, Version 2.0'
76+
url = 'https://www.apache.org/licenses/LICENSE-2.0.txt'
77+
distribution = 'repo'
78+
}
79+
}
80+
81+
scm {
82+
url = 'scm:git@github.com:apache/grails-core.git'
83+
connection = 'scm:git@github.com:apache/grails-core.git'
84+
developerConnection = 'scm:git@github.com:apache/grails-core.git'
85+
}
86+
87+
developers {
88+
developer {
89+
id = 'graemerocher'
90+
name = 'Graeme Rocher'
91+
}
92+
developer {
93+
id = 'jeffscottbrown'
94+
name = 'Jeff Brown'
95+
}
96+
developer {
97+
id = 'puneetbehl'
98+
name = 'Puneet Behl'
99+
}
100+
}
101+
}
102+
}
103+
}
104+
}
105+
106+
apply {
107+
from rootProject.layout.projectDirectory.file('gradle/java-config.gradle')
108+
from rootProject.layout.projectDirectory.file('gradle/docs-config.gradle')
109+
}
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.grails.gradle.plugin.run
20+
21+
import groovy.transform.CompileStatic
22+
import org.gradle.api.DefaultTask
23+
import org.gradle.api.Project
24+
import org.gradle.api.file.FileCollection
25+
import org.gradle.api.file.RegularFile
26+
import org.gradle.api.plugins.ExtraPropertiesExtension
27+
import org.gradle.api.provider.Provider
28+
import org.gradle.api.tasks.CacheableTask
29+
import org.gradle.api.tasks.InputFiles
30+
import org.gradle.api.tasks.OutputFile
31+
import org.gradle.api.tasks.PathSensitive
32+
import org.gradle.api.tasks.PathSensitivity
33+
import org.gradle.api.tasks.SourceSet
34+
import org.gradle.api.tasks.SourceSetOutput
35+
import org.gradle.api.tasks.TaskAction
36+
import org.grails.gradle.plugin.util.SourceSets
37+
import org.grails.io.support.MainClassFinder
38+
import org.springframework.boot.gradle.dsl.SpringBootExtension
39+
import org.springframework.boot.gradle.plugin.SpringBootPlugin
40+
41+
/**
42+
* A task that finds the main task, differs slightly from Boot's version as expects a subclass of GrailsConfiguration
43+
*
44+
* @author Graeme Rocher
45+
* @since 3.0
46+
*/
47+
@CompileStatic
48+
@CacheableTask
49+
class FindMainClassTask extends DefaultTask {
50+
51+
@TaskAction
52+
void setMainClassProperty() {
53+
Project project = this.project
54+
55+
def bootRunTask = project.tasks.findByName('bootRun')
56+
if (!bootRunTask || !bootRunTask.enabled) {
57+
project.logger.info('The bootRun task does not exist or is disabled, so this must not be a runnable grails application. Skipping finding main class.')
58+
return
59+
}
60+
61+
def bootJarTask = project.tasks.findByName(SpringBootPlugin.BOOT_JAR_TASK_NAME)
62+
def bootWarTask = project.tasks.findByName(SpringBootPlugin.BOOT_WAR_TASK_NAME)
63+
if ((!bootJarTask || !bootJarTask.enabled) && (!bootWarTask || !bootWarTask.enabled)) {
64+
project.logger.info('There is neither a {} or {} task that will run. Skipping finding main Application class.', SpringBootPlugin.BOOT_JAR_TASK_NAME, SpringBootPlugin.BOOT_WAR_TASK_NAME)
65+
return
66+
}
67+
68+
String mainClass = findMainClass()
69+
if (mainClass) {
70+
def extraProperties = project.extensions.getByType(ExtraPropertiesExtension)
71+
extraProperties.set('mainClassName', mainClass)
72+
73+
def springBootExtension = project.extensions.getByType(SpringBootExtension)
74+
springBootExtension.mainClass.convention(mainClass)
75+
} else {
76+
project.logger.warn('No main class found. Please set \'springBoot.mainClass\'.')
77+
}
78+
}
79+
80+
@InputFiles
81+
@PathSensitive(PathSensitivity.RELATIVE)
82+
FileCollection getClassesDirs() {
83+
SourceSet mainSourceSet = SourceSets.findMainSourceSet(project)
84+
if(mainSourceSet) {
85+
return resolveClassesDirs(mainSourceSet.output, project)
86+
}
87+
88+
project.files(project.layout.buildDirectory.dir('classes/main'))
89+
}
90+
91+
@OutputFile
92+
Provider<RegularFile> getMainClassCacheFile() {
93+
project.layout.buildDirectory.file('resolvedMainClassName')
94+
}
95+
96+
protected String findMainClass() {
97+
Project project = this.project
98+
99+
File buildDir = project.layout.buildDirectory.get().asFile
100+
buildDir.mkdirs()
101+
102+
File mainClassFile = getMainClassCacheFile().getOrNull()?.asFile
103+
if (mainClassFile.exists()) {
104+
return mainClassFile.text
105+
} else {
106+
// Look up the main source set.
107+
SourceSet mainSourceSet = SourceSets.findMainSourceSet(project)
108+
if (!mainSourceSet) {
109+
return null
110+
}
111+
112+
MainClassFinder mainClassFinder = createMainClassFinder()
113+
// Get the directories from which to try to find the main class.
114+
Set<File> classesDirs = getClassesDirs().files
115+
String mainClass = null
116+
for (File classesDir in classesDirs) {
117+
mainClass = mainClassFinder.findMainClass(classesDir)
118+
if (mainClass != null) {
119+
mainClassFile.text = mainClass
120+
break
121+
}
122+
}
123+
if (mainClass == null) {
124+
// Fallback attempt on a legacy directory.
125+
mainClass = mainClassFinder.findMainClass(project.layout.buildDirectory.dir('classes/groovy/main').getOrNull()?.asFile)
126+
if (mainClass != null) {
127+
mainClassFile.text = mainClass
128+
} else {
129+
if (project.plugins.hasPlugin('org.grails.gradle.plugin.core.GrailsPluginGradlePlugin')) {
130+
// this is ok if the project is a plugin because it's likely not going to be a runnable grails app
131+
project.logger.lifecycle('WARNING: this plugin project does not have an Application.class and thus the bootJar / bootRun will be invalid.')
132+
return null
133+
}
134+
135+
throw new RuntimeException('Could not find Application main class. Please set \'springBoot.mainClass\' or disable BootJar & BootArchive tasks.')
136+
}
137+
}
138+
return mainClass
139+
}
140+
}
141+
142+
protected FileCollection resolveClassesDirs(SourceSetOutput output, Project project) {
143+
output?.classesDirs ?: project.files(project.layout.buildDirectory.dir('classes/main'))
144+
}
145+
146+
protected MainClassFinder createMainClassFinder() {
147+
new MainClassFinder()
148+
}
149+
}

grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/util/SourceSets.groovy renamed to grails-gradle/tasks/src/main/groovy/org/grails/gradle/plugin/util/SourceSets.groovy

File renamed without changes.

0 commit comments

Comments
 (0)