@@ -22,19 +22,16 @@ import org.gradle.api.Plugin
2222import org.gradle.api.Project
2323import org.gradle.api.Task
2424import org.gradle.api.artifacts.Configuration
25- import org.gradle.api.attributes.AttributeCompatibilityRule
26- import org.gradle.api.attributes.Bundling
2725import org.gradle.api.attributes.Category
28- import org.gradle.api.attributes.CompatibilityCheckDetails
29- import org.gradle.api.attributes.LibraryElements
3026import org.gradle.api.attributes.Usage
31- import org.gradle.api.component.AdhocComponentWithVariants
3227import org.gradle.api.component.SoftwareComponentFactory
3328import org.gradle.api.file.CopySpec
3429import org.gradle.api.file.Directory
3530import org.gradle.api.file.SyncSpec
3631import org.gradle.api.model.ObjectFactory
3732import org.gradle.api.plugins.BasePlugin
33+ import org.gradle.api.plugins.GroovyPlugin
34+ import org.gradle.api.plugins.JavaLibraryPlugin
3835import org.gradle.api.tasks.TaskProvider
3936import org.gradle.api.tasks.bundling.Jar
4037import org.grails.gradle.plugin.profiles.tasks.ProfileCompilerTask
@@ -52,11 +49,8 @@ import static org.gradle.api.plugins.BasePlugin.BUILD_GROUP
5249@CompileStatic
5350class GrailsProfileGradlePlugin implements Plugin<Project > {
5451
55- static final String USAGE_PROFILE_NAME = ' profile-runtime'
56- static final String COMPONENT_NAME = ' profile'
57- static final String RUNTIME_API_CONFIGURATION = ' profileRuntimeApi'
58- // to add dependencies for that profile's scripts
59- static final String RUNTIME_ONLY_CONFIGURATION = ' profileRuntimeOnly' // to be used to extend profiles
52+ // to be used to extend profiles
53+ static final String PROFILE_API_CONFIGURATION = ' profileRuntimeApi'
6054
6155 private final SoftwareComponentFactory softwareComponentFactory
6256 private final ObjectFactory objectFactory
@@ -70,50 +64,26 @@ class GrailsProfileGradlePlugin implements Plugin<Project> {
7064 @Override
7165 void apply (Project project ) {
7266 project. pluginManager. apply(BasePlugin )
73-
74- Usage profileUsage = objectFactory. named(Usage , USAGE_PROFILE_NAME )
75-
76- project. dependencies. attributesSchema {
77- it. attribute(Usage . USAGE_ATTRIBUTE ) {
78- it. compatibilityRules. add(JavaRuntimeCompatibility )
67+ project. pluginManager. apply(GroovyPlugin )
68+ project. pluginManager. apply(JavaLibraryPlugin )
69+
70+ NamedDomainObjectProvider<Configuration > runtimeOnlyConfiguration = project. configurations. register(PROFILE_API_CONFIGURATION )
71+ runtimeOnlyConfiguration. configure { Configuration config ->
72+ config. description = ' Profiles to inherit for this profile project'
73+ config. canBeConsumed = true
74+ config. canBeResolved = true
75+
76+ config. attributes {
77+ it. attribute(Usage . USAGE_ATTRIBUTE , project. objects. named(Usage , Usage . JAVA_RUNTIME ))
78+ it. attribute(Category . CATEGORY_ATTRIBUTE , project. objects. named(Category , Category . LIBRARY ))
7979 }
8080 }
8181
82- AdhocComponentWithVariants profileComponent = softwareComponentFactory . adhoc( COMPONENT_NAME )
83- project . components . add(profileComponent)
82+ project . configurations . named( " apiElements " )
83+ .configure { it . extendsFrom(runtimeOnlyConfiguration . get()) }
8484
85- NamedDomainObjectProvider<Configuration > runtimeApiConfiguration = project. configurations. register(RUNTIME_API_CONFIGURATION )
86- runtimeApiConfiguration. configure { Configuration it ->
87- it. description = ' Dependencies exported transitively to other profile projects'
88- it. canBeConsumed = false
89- it. canBeResolved = false
90- it. attributes {
91- it. attribute(Usage . USAGE_ATTRIBUTE , profileUsage)
92- it. attribute(LibraryElements . LIBRARY_ELEMENTS_ATTRIBUTE , objectFactory. named(LibraryElements , LibraryElements . CLASSES ))
93- it. attribute(Category . CATEGORY_ATTRIBUTE , objectFactory. named(Category , Category . LIBRARY ))
94- it. attribute(Bundling . BUNDLING_ATTRIBUTE , objectFactory. named(Bundling , Bundling . EXTERNAL ))
95- }
96- profileComponent. addVariantsFromConfiguration(it) {
97- it. mapToMavenScope(' compile' )
98- }
99- }
100-
101- NamedDomainObjectProvider<Configuration > runtimeOnlyConfiguration = project. configurations. register(RUNTIME_ONLY_CONFIGURATION )
102- runtimeOnlyConfiguration. configure { Configuration it ->
103- it. description = ' Dependencies required to compile a profile project'
104- it. canBeConsumed = true
105- it. canBeResolved = true
106- it. extendsFrom(runtimeApiConfiguration. get())
107- it. attributes {
108- it. attribute(Usage . USAGE_ATTRIBUTE , profileUsage)
109- it. attribute(LibraryElements . LIBRARY_ELEMENTS_ATTRIBUTE , objectFactory. named(LibraryElements , LibraryElements . JAR ))
110- it. attribute(Category . CATEGORY_ATTRIBUTE , objectFactory. named(Category , Category . LIBRARY ))
111- it. attribute(Bundling . BUNDLING_ATTRIBUTE , objectFactory. named(Bundling , Bundling . EXTERNAL ))
112- }
113- profileComponent. addVariantsFromConfiguration(it) {
114- it. mapToMavenScope(' runtime' )
115- }
116- }
85+ project. configurations. named(" runtimeElements" )
86+ .configure { it. extendsFrom(runtimeOnlyConfiguration. get()) }
11787
11888 TaskProvider<Task > processProfileResourcesTask = project. tasks. register(' processProfileResources' )
11989 processProfileResourcesTask. configure { Task task ->
@@ -203,22 +173,21 @@ class GrailsProfileGradlePlugin implements Plugin<Project> {
203173 }
204174 return null
205175 }
206- it. classpath = runtimeOnlyConfiguration. get()
176+ it. classpath = project . files( runtimeOnlyConfiguration. get(), project . configurations . named( ' runtimeClasspath ' ) . get() )
207177 }
208178
209- TaskProvider<Jar > jarTask = project. tasks. register( ' profileJar ' , Jar )
179+ TaskProvider<Jar > jarTask = project. tasks. named( ' jar ' , Jar )
210180 jarTask. configure { Jar jar ->
211- jar. group = BUILD_GROUP
212- jar. dependsOn(processProfileResourcesTask, compileTask, project. tasks. named(' jar' , Jar ). orNull)
181+ jar. dependsOn(processProfileResourcesTask, compileTask)
213182
214183 jar. from(project. files(project. layout. buildDirectory. dir(' resources/profile' ), project. layout. buildDirectory. dir(' classes/profile' )))
215- jar. destinationDirectory. set(project. layout. buildDirectory. dir(' libs' ))
216- jar. description = ' Assembles a jar archive containing the profile classes.'
217184 jar. reproducibleFileOrder = true
218185 jar. preserveFileTimestamps = false
186+ jar. dirMode = 0755 // To avoid platform specific defaults
187+ jar. fileMode = 0644 // to avoid platform specific defaults
219188 }
220189
221- TaskProvider<Jar > sourcesJarTask = project. tasks. register(' sourcesProfileJar ' , Jar )
190+ TaskProvider<Jar > sourcesJarTask = project. tasks. register(' sourcesJar ' , Jar )
222191 sourcesJarTask. configure { Jar jar ->
223192 jar. from(project. layout. projectDirectory. dir(' commands' ))
224193 if (project. file(' profile.yml' ). exists()) {
@@ -235,7 +204,8 @@ class GrailsProfileGradlePlugin implements Plugin<Project> {
235204 jar. description = ' Assembles a jar archive containing the profile sources.'
236205 jar. reproducibleFileOrder = true
237206 jar. preserveFileTimestamps = false
238- jar. group = BUILD_GROUP
207+ jar. dirMode = 0755 // To avoid platform specific defaults
208+ jar. fileMode = 0644 // to avoid platform specific defaults
239209 }
240210
241211 def profileReadme = project. layout. buildDirectory. file(' profile.txt' )
@@ -251,8 +221,17 @@ class GrailsProfileGradlePlugin implements Plugin<Project> {
251221 }
252222 }
253223
254- TaskProvider<Jar > javadocJarTask = project. tasks. register(' javadocProfileJar' , Jar )
224+ project. tasks. named(' javadoc' ). configure {
225+ it. enabled = false // will replace the java doc
226+ }
227+
228+ TaskProvider<Jar > javadocJarTask = project. tasks. register(' javadocJar' , Jar )
255229 javadocJarTask. configure { Jar jar ->
230+ jar. reproducibleFileOrder = true
231+ jar. preserveFileTimestamps = false
232+ jar. dirMode = 0755 // To avoid platform specific defaults
233+ jar. fileMode = 0644 // to avoid platform specific defaults
234+
256235 jar. dependsOn(readmeGeneration)
257236 // https://central.sonatype.org/publish/requirements/#supply-javadoc-and-sources
258237 jar. from(profileReadme) { CopySpec spec ->
@@ -262,25 +241,6 @@ class GrailsProfileGradlePlugin implements Plugin<Project> {
262241 jar. destinationDirectory. set(new File (project. layout. buildDirectory. asFile. get(), ' libs' ))
263242 jar. description = ' Assembles a jar archive containing the profile javadoc.'
264243 jar. group = BUILD_GROUP
265- jar. reproducibleFileOrder = true
266- jar. preserveFileTimestamps = false
267- }
268-
269- project. tasks. named(' assemble' ). configure { Task it ->
270- it. dependsOn(jarTask)
271- }
272- }
273- }
274-
275- /**
276- * I'm not sure why a separate configuration was originally created for the profiles, but maybe they are combined
277- * into a single gradle project. For compatibility purposes, treat java-runtime as a usable substitute
278- */
279- class JavaRuntimeCompatibility implements AttributeCompatibilityRule<Usage > {
280- @Override
281- void execute (CompatibilityCheckDetails<Usage > d ) {
282- if (d. consumerValue. name == GrailsProfileGradlePlugin . USAGE_PROFILE_NAME && d. producerValue. name == Usage . JAVA_RUNTIME ) {
283- d. compatible()
284244 }
285245 }
286246}
0 commit comments