-
-
Notifications
You must be signed in to change notification settings - Fork 968
Centralizing Gradle Logic - java-config #15269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+719
−572
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ee76857
removing `java-config.gradle` in favor of plugin
jdaugherty 7953e13
remove source of duplicate sourceset inclusion in source jars
jdaugherty c8a6efa
use SharedPropertiesPlugin where possible and avoid manual loading of…
jdaugherty 957ff56
remove manual gradle.properties lookup from buildSrcs
jdaugherty f5794ee
Add missing license headers
jdaugherty 883ecc7
reformatting code
jdaugherty f9466f6
feedback - switch to register() for implicit typing
jdaugherty 2921aa2
feedback - formatting & various clean-up
jdaugherty 068553e
feedback - replace java-library with groovy where groovy source is us…
jdaugherty 1234616
Revert "feedback - replace java-library with groovy where groovy sour…
jdaugherty ec896d5
feedback - update comment to reflect the version is matching the bom …
jdaugherty 018415b
feedback - remove java-library from grails plugins
jdaugherty e121dee
feedback - remove java plugin from wrapper
jdaugherty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/CompilePlugin.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| /* | ||
| * 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.apache.grails.buildsrc | ||
|
|
||
| import java.nio.charset.StandardCharsets | ||
| import java.util.concurrent.atomic.AtomicBoolean | ||
|
|
||
| import groovy.transform.CompileStatic | ||
|
|
||
| import org.gradle.api.Plugin | ||
| import org.gradle.api.Project | ||
| import org.gradle.api.file.DuplicatesStrategy | ||
| import org.gradle.api.plugins.JavaPluginExtension | ||
| import org.gradle.api.tasks.bundling.AbstractArchiveTask | ||
| import org.gradle.api.tasks.bundling.Jar | ||
| import org.gradle.api.tasks.compile.GroovyCompile | ||
| import org.gradle.api.tasks.compile.JavaCompile | ||
| import org.gradle.api.tasks.javadoc.Javadoc | ||
| import org.gradle.external.javadoc.StandardJavadocDocletOptions | ||
|
|
||
| import static org.apache.grails.buildsrc.GradleUtils.lookupPropertyByType | ||
|
|
||
| @CompileStatic | ||
| class CompilePlugin implements Plugin<Project> { | ||
|
|
||
| @Override | ||
| void apply(Project project) { | ||
| def initialized = new AtomicBoolean(false) | ||
| project.plugins.withId('java') { // java (applied when groovy is applied) or java-library | ||
| if (initialized.compareAndSet(false, true)) { | ||
| configureCompile(project) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static void configureCompile(Project project) { | ||
| configureJavaVersion(project) | ||
| configureJars(project) | ||
| configureCompiler(project) | ||
| configureReproducible(project) | ||
| } | ||
|
|
||
| private static void configureJavaVersion(Project project) { | ||
| project.tasks.withType(JavaCompile).configureEach { | ||
| it.options.release.set(lookupPropertyByType(project, 'javaVersion', Integer)) | ||
| } | ||
| } | ||
|
|
||
| private static void configureJars(Project project) { | ||
| project.extensions.configure(JavaPluginExtension) { | ||
| it.withJavadocJar() | ||
| it.withSourcesJar() | ||
| } | ||
|
|
||
| // Grails determines the grails version via the META-INF/MANIFEST.MF file | ||
| // Note: we exclude attributes such as Built-By, Build-Jdk, Created-By to ensure the build is reproducible. | ||
| project.tasks.withType(Jar).configureEach { Jar jar -> | ||
| if (lookupPropertyByType(project, 'skipJavaComponent', Boolean)) { | ||
| jar.enabled = false | ||
| return | ||
| } | ||
|
|
||
| jar.manifest.attributes( | ||
| 'Implementation-Title': 'Apache Grails', | ||
| 'Implementation-Version': lookupPropertyByType(project, 'grailsVersion', String), | ||
| 'Implementation-Vendor': 'grails.apache.org' | ||
| ) | ||
| // Explicitly fail since duplicates indicate a double configuration that needs fixed | ||
| jar.duplicatesStrategy = DuplicatesStrategy.FAIL | ||
| } | ||
| } | ||
|
|
||
| private static void configureCompiler(Project project) { | ||
| project.tasks.withType(JavaCompile).configureEach { | ||
| // Preserve method parameter names in Groovy/Java classes for IDE parameter hints & bean reflection metadata. | ||
| it.options.compilerArgs.add('-parameters') | ||
| // encoding needs to be the same since it's different across platforms | ||
| it.options.encoding = StandardCharsets.UTF_8.name() | ||
| it.options.fork = true | ||
| it.options.forkOptions.jvmArgs = ['-Xms128M', '-Xmx2G'] | ||
| } | ||
|
|
||
| project.plugins.withId('groovy') { | ||
| project.tasks.withType(GroovyCompile).configureEach { | ||
| // encoding needs to be the same since it's different across platforms | ||
jdaugherty marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| it.groovyOptions.encoding = StandardCharsets.UTF_8.name() | ||
| // Preserve method parameter names in Groovy/Java classes for IDE parameter hints & bean reflection metadata. | ||
| it.groovyOptions.parameters = true | ||
| // encoding needs to be the same since it's different across platforms | ||
jdaugherty marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| it.options.encoding = StandardCharsets.UTF_8.name() | ||
| it.options.fork = true | ||
| it.options.forkOptions.jvmArgs = ['-Xms128M', '-Xmx2G'] | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static void configureReproducible(Project project) { | ||
| project.tasks.withType(Javadoc).configureEach { Javadoc it -> | ||
| def options = it.options as StandardJavadocDocletOptions | ||
| options.noTimestamp = true | ||
| options.bottom = "Generated ${lookupPropertyByType(project, 'formattedBuildDate', String)} (UTC)" | ||
| } | ||
|
|
||
| // Any jar, zip, or archive should be reproducible | ||
| // No longer needed after https://github.com/gradle/gradle/issues/30871 | ||
| project.tasks.withType(AbstractArchiveTask).configureEach { | ||
| it.preserveFileTimestamps = false // to prevent timestamp mismatches | ||
| it.reproducibleFileOrder = true // to keep the same ordering | ||
| // to avoid platform specific defaults, set the permissions consistently | ||
| it.filePermissions { permissions -> | ||
| permissions.unix(0644) | ||
| } | ||
| it.dirPermissions { permissions -> | ||
| permissions.unix(0755) | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/SharedPropertyPlugin.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /* | ||
| * 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.apache.grails.buildsrc | ||
|
|
||
| import groovy.transform.CompileStatic | ||
|
|
||
| import org.gradle.api.Plugin | ||
| import org.gradle.api.Project | ||
| import org.gradle.api.file.Directory | ||
| import org.gradle.api.plugins.ExtraPropertiesExtension | ||
|
|
||
| import static org.apache.grails.buildsrc.GradleUtils.findRootGrailsCoreDir | ||
|
|
||
| /** | ||
| * Gradle can't share properties across buildSrc or composite projects. This plugin ensures that properties not defined | ||
| * in this project, but are in the root grails-core project, are accessible in this project. This plugin must be applied | ||
| * prior to the access of any property for it to work properly | ||
| */ | ||
| @CompileStatic | ||
| class SharedPropertyPlugin implements Plugin<Project> { | ||
|
|
||
| @Override | ||
| void apply(Project project) { | ||
| populateParentProperties( | ||
| project.layout.projectDirectory, | ||
| findRootGrailsCoreDir(project), | ||
| project.extensions.extraProperties, | ||
| project | ||
| ) | ||
| } | ||
|
|
||
| void populateParentProperties(Directory projectDirectory, Directory rootDirectory, ExtraPropertiesExtension ext, Project project) { | ||
| if (!rootDirectory) { | ||
| throw new IllegalStateException('Could not locate the root directory to populate up to') | ||
| } | ||
|
|
||
| if (projectDirectory.file('gradle.properties').asFile.exists()) { | ||
| def propertyPath = rootDirectory.asFile.relativePath(projectDirectory.asFile) | ||
| project.logger.info('Using properties from grails-core/{}gradle.properties', propertyPath ? "${propertyPath}/" : '') | ||
| projectDirectory.file('gradle.properties').asFile.withInputStream { | ||
| Properties rootProperties = new Properties() | ||
| rootProperties.load(it) | ||
|
|
||
| for (String key : rootProperties.stringPropertyNames()) { | ||
| if (!ext.has(key)) { | ||
| ext.set(key, rootProperties.getProperty(key)) | ||
| } | ||
| } | ||
|
|
||
| if (rootProperties.containsKey('projectVersion')) { | ||
| ext.set('grailsVersion', rootProperties.getProperty('projectVersion')) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (projectDirectory.asFile.absolutePath != rootDirectory.asFile.absolutePath) { | ||
| populateParentProperties(projectDirectory.dir('..'), rootDirectory, ext, project) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.