Skip to content
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
8 changes: 4 additions & 4 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ jobs:
develocity-access-key: ${{ secrets.GRAILS_DEVELOCITY_ACCESS_KEY }}
- name: "🔨 Build project"
run: >
./gradlew build :grails-shell-cli:installDist groovydoc
./gradlew :grails-bom:publishMavenPublicationToLocalBomRepository build :grails-shell-cli:installDist groovydoc
--continue --stacktrace -PonlyCoreTests
functional:
name: "Functional Tests"
Expand All @@ -117,7 +117,7 @@ jobs:
develocity-access-key: ${{ secrets.GRAILS_DEVELOCITY_ACCESS_KEY }}
- name: "🏃 Run Functional Tests"
run: >
./gradlew bootJar check
./gradlew :grails-bom:publishMavenPublicationToLocalBomRepository bootJar check
--continue --stacktrace
-PonlyFunctionalTests
-PskipHibernate5Tests
Expand Down Expand Up @@ -149,7 +149,7 @@ jobs:
env:
GITHUB_MAVEN_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
run: >
./gradlew bootJar cleanTest check
./gradlew :grails-bom:publishMavenPublicationToLocalBomRepository bootJar cleanTest check
--continue --stacktrace
-PonlyMongodbTests
-PmongodbContainerVersion=${{ matrix.mongodb-version }}
Expand Down Expand Up @@ -179,7 +179,7 @@ jobs:
env:
GITHUB_MAVEN_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
run: >
./gradlew bootJar cleanTest check
./gradlew :grails-bom:publishMavenPublicationToLocalBomRepository bootJar cleanTest check
--continue --stacktrace
-PonlyHibernate5Tests
publishGradle:
Expand Down
2 changes: 1 addition & 1 deletion grails-gradle/gradle/e2eTest.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ e2eTestTask.configure { Test it ->
}
it.beforeTest { descriptor -> logger.quiet ' -- $descriptor' }

it.dependsOn 'publishAllPublicationsToTestCaseMavenRepoRepository', ':grails-gradle-bom:publishAllPublicationsToTestCaseMavenRepoRepository'
it.dependsOn 'publishAllPublicationsToTestCaseMavenRepoRepository', ':grails-gradle-tasks:publishAllPublicationsToTestCaseMavenRepoRepository', ':grails-gradle-bom:publishAllPublicationsToTestCaseMavenRepoRepository'
}

tasks.named('check').configure {
Expand Down
7 changes: 3 additions & 4 deletions grails-gradle/plugins/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ dependencies {
// compile grails-gradle-plugin with the Groovy version provided by Gradle
// to ensure build compatibility with Gradle, currently Groovy 3.0.x
// see: https://docs.gradle.org/current/userguide/compatibility.html#groovy
// TODO: tasks are isolated as of Gradle 7 so we must expose the version of the groovy.
// We could upgrade to groovy 4 for the tasks, but gradle plugins are not isolated and still
// need groovy 3.
implementation "org.codehaus.groovy:groovy"
compileOnly "org.codehaus.groovy:groovy"

implementation project(':grails-gradle-tasks')

implementation project(':grails-gradle-model'), {
exclude group: 'org.apache.groovy'
Expand Down
5 changes: 4 additions & 1 deletion grails-gradle/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,7 @@ include 'grails-gradle-model'
project(':grails-gradle-model').projectDir = file('model')

include 'grails-docs-core'
project(':grails-docs-core').projectDir = file('docs-core')
project(':grails-docs-core').projectDir = file('docs-core')

include 'grails-gradle-tasks'
project(':grails-gradle-tasks').projectDir = file('tasks')
17 changes: 17 additions & 0 deletions grails-gradle/tasks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!--
SPDX-License-Identifier: Apache-2.0

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

Grails Gradle Task exists due to newer versions of Gradle isolating classpaths of Gradle tasks.
109 changes: 109 additions & 0 deletions grails-gradle/tasks/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

plugins {
id 'groovy'
id 'java-gradle-plugin'
id 'maven-publish'
}

version = projectVersion
group = 'org.apache.grails'

dependencies {
implementation platform(project(':grails-gradle-bom'))

implementation "org.codehaus.groovy:groovy"

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

implementation 'io.github.gradle-nexus:publish-plugin'
implementation 'org.springframework.boot:spring-boot-gradle-plugin'
}

publishing {
if (!isReleaseVersion) {
repositories {
maven {
credentials {
username = System.getenv('MAVEN_PUBLISH_USERNAME')
password = System.getenv('MAVEN_PUBLISH_PASSWORD')
}
url = System.getenv('MAVEN_PUBLISH_URL') ?: 'https://repository.apache.org/content/repositories/snapshots'
}
}
}

// used for e2e testing
// publishAllPublicationsToTestCaseMavenRepoRepository
repositories {
maven {
name = 'TestCaseMavenRepo'
url = rootProject.layout.buildDirectory.dir('local-maven')
}
}

publications {
pluginMaven(MavenPublication) {
pom {
name = 'Grails Gradle Tasks'
description = 'A Gradle tasks for Grails gradle plugins'

url = 'https://github.com/apache/grails-core'

licenses {
license {
name = 'The Apache Software License, Version 2.0'
url = 'https://www.apache.org/licenses/LICENSE-2.0.txt'
distribution = 'repo'
}
}

scm {
url = 'scm:git@github.com:apache/grails-core.git'
connection = 'scm:git@github.com:apache/grails-core.git'
developerConnection = 'scm:git@github.com:apache/grails-core.git'
}

developers {
developer {
id = 'graemerocher'
name = 'Graeme Rocher'
}
developer {
id = 'jeffscottbrown'
name = 'Jeff Brown'
}
developer {
id = 'puneetbehl'
name = 'Puneet Behl'
}
}
}
}
}
}

apply {
from rootProject.layout.projectDirectory.file('gradle/java-config.gradle')
from rootProject.layout.projectDirectory.file('gradle/docs-config.gradle')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.grails.gradle.plugin.run

import groovy.transform.CompileStatic
import org.gradle.api.DefaultTask
import org.gradle.api.Project
import org.gradle.api.file.FileCollection
import org.gradle.api.file.RegularFile
import org.gradle.api.plugins.ExtraPropertiesExtension
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.SourceSetOutput
import org.gradle.api.tasks.TaskAction
import org.grails.gradle.plugin.util.SourceSets
import org.grails.io.support.MainClassFinder
import org.springframework.boot.gradle.dsl.SpringBootExtension
import org.springframework.boot.gradle.plugin.SpringBootPlugin

/**
* A task that finds the main task, differs slightly from Boot's version as expects a subclass of GrailsConfiguration
*
* @author Graeme Rocher
* @since 3.0
*/
@CompileStatic
@CacheableTask
class FindMainClassTask extends DefaultTask {

@TaskAction
void setMainClassProperty() {
Project project = this.project

def bootRunTask = project.tasks.findByName('bootRun')
if (!bootRunTask || !bootRunTask.enabled) {
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.')
return
}

def bootJarTask = project.tasks.findByName(SpringBootPlugin.BOOT_JAR_TASK_NAME)
def bootWarTask = project.tasks.findByName(SpringBootPlugin.BOOT_WAR_TASK_NAME)
if ((!bootJarTask || !bootJarTask.enabled) && (!bootWarTask || !bootWarTask.enabled)) {
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)
return
}

String mainClass = findMainClass()
if (mainClass) {
def extraProperties = project.extensions.getByType(ExtraPropertiesExtension)
extraProperties.set('mainClassName', mainClass)

def springBootExtension = project.extensions.getByType(SpringBootExtension)
springBootExtension.mainClass.convention(mainClass)
} else {
project.logger.warn('No main class found. Please set \'springBoot.mainClass\'.')
}
}

@InputFiles
@PathSensitive(PathSensitivity.RELATIVE)
FileCollection getClassesDirs() {
SourceSet mainSourceSet = SourceSets.findMainSourceSet(project)
if(mainSourceSet) {
return resolveClassesDirs(mainSourceSet.output, project)
}

project.files(project.layout.buildDirectory.dir('classes/main'))
}

@OutputFile
Provider<RegularFile> getMainClassCacheFile() {
project.layout.buildDirectory.file('resolvedMainClassName')
}

protected String findMainClass() {
Project project = this.project

File buildDir = project.layout.buildDirectory.get().asFile
buildDir.mkdirs()

File mainClassFile = getMainClassCacheFile().getOrNull()?.asFile
if (mainClassFile.exists()) {
return mainClassFile.text
} else {
// Look up the main source set.
SourceSet mainSourceSet = SourceSets.findMainSourceSet(project)
if (!mainSourceSet) {
return null
}

MainClassFinder mainClassFinder = createMainClassFinder()
// Get the directories from which to try to find the main class.
Set<File> classesDirs = getClassesDirs().files
String mainClass = null
for (File classesDir in classesDirs) {
mainClass = mainClassFinder.findMainClass(classesDir)
if (mainClass != null) {
mainClassFile.text = mainClass
break
}
}
if (mainClass == null) {
// Fallback attempt on a legacy directory.
mainClass = mainClassFinder.findMainClass(project.layout.buildDirectory.dir('classes/groovy/main').getOrNull()?.asFile)
if (mainClass != null) {
mainClassFile.text = mainClass
} else {
if (project.plugins.hasPlugin('org.grails.gradle.plugin.core.GrailsPluginGradlePlugin')) {
// this is ok if the project is a plugin because it's likely not going to be a runnable grails app
project.logger.lifecycle('WARNING: this plugin project does not have an Application.class and thus the bootJar / bootRun will be invalid.')
return null
}

throw new RuntimeException('Could not find Application main class. Please set \'springBoot.mainClass\' or disable BootJar & BootArchive tasks.')
}
}
return mainClass
}
}

protected FileCollection resolveClassesDirs(SourceSetOutput output, Project project) {
output?.classesDirs ?: project.files(project.layout.buildDirectory.dir('classes/main'))
}

protected MainClassFinder createMainClassFinder() {
new MainClassFinder()
}
}
Loading