Skip to content

Commit 17bedc3

Browse files
committed
Gradle - use runtime config for exploded run
1 parent f4eed94 commit 17bedc3

File tree

1 file changed

+41
-27
lines changed

1 file changed

+41
-27
lines changed

grails-gradle-plugin/src/main/groovy/org/grails/gradle/plugin/core/GrailsPluginGradlePlugin.groovy

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,41 @@
1+
/*
2+
* Copyright 2014 original authors
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+
* http://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+
*/
116
package org.grails.gradle.plugin.core
217

18+
import grails.util.Environment
319
import groovy.transform.CompileStatic
420
import org.gradle.api.Project
521
import org.gradle.api.Task
22+
import org.gradle.api.artifacts.Configuration
623
import org.gradle.api.artifacts.PublishArtifact
24+
import org.gradle.api.artifacts.dsl.ArtifactHandler
725
import org.gradle.api.internal.tasks.DefaultTaskDependency
826
import org.gradle.api.tasks.Copy
927
import org.gradle.api.tasks.JavaExec
28+
import org.gradle.api.tasks.SourceSetContainer
29+
import org.gradle.api.tasks.TaskContainer
1030
import org.gradle.api.tasks.TaskDependency
1131
import org.gradle.api.tasks.bundling.Jar
1232
import org.gradle.api.tasks.compile.GroovyCompile
1333
import org.gradle.language.jvm.tasks.ProcessResources
1434
import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
35+
import org.grails.gradle.plugin.util.SourceSets
1536

1637
import javax.inject.Inject
17-
/*
18-
* Copyright 2014 original authors
19-
*
20-
* Licensed under the Apache License, Version 2.0 (the "License");
21-
* you may not use this file except in compliance with the License.
22-
* You may obtain a copy of the License at
23-
*
24-
* http://www.apache.org/licenses/LICENSE-2.0
25-
*
26-
* Unless required by applicable law or agreed to in writing, software
27-
* distributed under the License is distributed on an "AS IS" BASIS,
28-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29-
* See the License for the specific language governing permissions and
30-
* limitations under the License.
31-
*/
38+
3239

3340
/**
3441
* A Gradle plugin for Grails plugins
@@ -76,35 +83,42 @@ class GrailsPluginGradlePlugin extends GrailsGradlePlugin {
7683
def allConfigurations = project.configurations
7784

7885
def explodedConfig = allConfigurations.create(configurationName)
79-
explodedConfig.extendsFrom(allConfigurations.findByName('compile'))
86+
87+
def parent = allConfigurations.findByName('runtime')
88+
if(Environment.isDevelopmentRun()) {
89+
parent.artifacts.clear()
90+
}
91+
explodedConfig.extendsFrom(parent)
8092
// add the subproject classes as outputs
81-
GroovyCompile groovyCompile = (GroovyCompile)project.tasks.findByName('compileGroovy')
82-
project.artifacts.add(configurationName, new ExplodedDir( groovyCompile.destinationDir, groovyCompile) )
93+
def allTasks = project.tasks
94+
GroovyCompile groovyCompile = (GroovyCompile) allTasks.findByName('compileGroovy')
95+
96+
def allArtifacts = project.artifacts
97+
allArtifacts.add(configurationName, new ExplodedDir( groovyCompile.destinationDir, groovyCompile) )
8398

8499
// add the subproject resources as outputs
85-
ProcessResources processResources = (ProcessResources)project.tasks.findByName("processResources")
86-
project.artifacts.add(configurationName, new ExplodedDir( processResources.destinationDir, processResources) )
100+
ProcessResources processResources = (ProcessResources) allTasks.findByName("processResources")
101+
allArtifacts.add(configurationName, new ExplodedDir( processResources.destinationDir, processResources) )
87102
}
88103

89104
@Override
90105
protected Task createBuildPropertiesTask(Project project) {
91106
// no-op
92107
}
93108

109+
@CompileStatic
94110
protected void configureSourcesJarTask(Project project) {
95111
def taskContainer = project.tasks
96112
if(taskContainer.findByName('sourcesJar') == null) {
97-
taskContainer.create("sourcesJar", Jar).configure {
98-
classifier = 'sources'
99-
from project.sourceSets.main.allSource
100-
}
113+
def jarTask = taskContainer.create("sourcesJar", Jar)
114+
jarTask.classifier = 'sources'
115+
jarTask.from SourceSets.findMainSourceSet(project).allSource
101116
}
102117
}
103118

104119
protected void configureAstSources(Project project) {
105-
def sourceSets = project.sourceSets
106-
def mainSourceSet = sourceSets.main
107-
120+
def mainSourceSet = SourceSets.findMainSourceSet(project)
121+
def sourceSets = SourceSets.findSourceSets(project)
108122
project.sourceSets {
109123
ast {
110124
groovy {

0 commit comments

Comments
 (0)