Skip to content
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

Improve build configuration time #41392

Merged
merged 44 commits into from
May 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
e23d207
work in progress
mark-vieira Apr 10, 2019
fd193d3
wip
mark-vieira Apr 10, 2019
0643838
more wip
mark-vieira Apr 10, 2019
5512fff
tweaks
mark-vieira Apr 17, 2019
58882ed
Merge remote-tracking branch 'mark-vieira/global-info-refactor' into …
mark-vieira Apr 17, 2019
fdbbb38
Convert BuildPlugin to static Groovy
mark-vieira Apr 19, 2019
90e4d40
Remove unnecessary Fips configuration
mark-vieira Apr 19, 2019
8b4c313
Merge remote-tracking branch 'origin/master' into global-info-refactor
mark-vieira Apr 19, 2019
a8fa5ca
Merge remote-tracking branch 'origin/master' into global-info-refactor
mark-vieira Apr 19, 2019
323f2e7
Remove usage of Java 11 API to maintain Java 8 compatibility
mark-vieira Apr 19, 2019
1341666
Checkstyle
mark-vieira Apr 19, 2019
3050799
Correctly configure target and source compatibility
mark-vieira Apr 19, 2019
202541a
Fixes for fipsJvm-specific config
mark-vieira Apr 19, 2019
f403411
Fix reference to BasePluginConvention
mark-vieira Apr 19, 2019
fdeb65f
Fix publishing plugin configuration
mark-vieira Apr 22, 2019
e0cdc2a
Build plugin and global info plugin are coupled, let's enforce that
mark-vieira Apr 22, 2019
99f2510
We need to apply it here as well, you know, ordering and stuff
mark-vieira Apr 22, 2019
b169755
Make sure compile conventions are applied to QA projects
mark-vieira Apr 22, 2019
e3c4be6
Just get compilation to work
mark-vieira Apr 22, 2019
60a7d97
Datastructure is no longer a Map
mark-vieira Apr 22, 2019
041fa32
Fix java home location
mark-vieira Apr 22, 2019
475054a
Merge remote-tracking branch 'origin/master' into global-info-refactor
mark-vieira May 2, 2019
35f0bd0
Merge remote-tracking branch 'origin/master' into global-info-refactor
mark-vieira May 8, 2019
20064e3
Fix issue with UP-TO-DATE reporting
mark-vieira May 8, 2019
26cc00d
Unused import
mark-vieira May 8, 2019
e3cb50a
Ensure fips jvm metadata is tracked as an output
mark-vieira May 8, 2019
f8096db
Merge remote-tracking branch 'origin/master' into global-info-refactor
mark-vieira May 8, 2019
6255824
Sort out issue with cluster start/stop ordering.
mark-vieira May 8, 2019
db86526
Read cluster settings at execution time
mark-vieira May 9, 2019
acec279
Remove unnecessarily usages of runJavaAsScript()
mark-vieira May 9, 2019
b30c87b
Merge remote-tracking branch 'origin/master' into global-info-refactor
mark-vieira May 9, 2019
3de9468
This should be immutable
mark-vieira May 9, 2019
70e5148
Remove unnecessary newline
mark-vieira May 9, 2019
9664bf5
Merge remote-tracking branch 'origin/master' into global-info-refactor
mark-vieira May 20, 2019
3907284
Merge remote-tracking branch 'origin/master' into global-info-refactor
mark-vieira May 21, 2019
69952e2
Deal with fallout from merging #41989
mark-vieira May 21, 2019
aa4bc82
Merge remote-tracking branch 'origin/master' into global-info-refactor
mark-vieira May 21, 2019
f7929ae
Address review feedback
mark-vieira May 22, 2019
1104f52
Keep java 8 compatibility for build-tools
mark-vieira May 22, 2019
1eafd8c
Reorder class members
mark-vieira May 22, 2019
c9299c1
Remove intermediary variable
mark-vieira May 22, 2019
8cc01e4
Check for existence of java home directories
mark-vieira May 22, 2019
19d6479
Merge remote-tracking branch 'origin/master' into global-info-refactor
mark-vieira May 22, 2019
3290640
Merge remote-tracking branch 'origin/master' into global-info-refactor
mark-vieira May 23, 2019
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
9 changes: 3 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import org.gradle.plugins.ide.eclipse.model.SourceFolder
plugins {
id 'com.gradle.build-scan' version '2.2.1'
id 'base'
id 'elasticsearch.global-build-info'
}
if (Boolean.valueOf(project.findProperty('org.elasticsearch.acceptScanTOS') ?: "false")) {
buildScan {
Expand Down Expand Up @@ -262,7 +263,7 @@ allprojects {
}

project.afterEvaluate {
configurations.all {
configurations.matching { it.canBeResolved }.all {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why wouldn't the config be necessary? Maybe worth adding a comment to explain.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's not point in doing substitutions on internal configurations that cannot be resolved. I think this is a bit moot anyway since all this is going to get ripped out as part of #42093.

resolutionStrategy.dependencySubstitution { DependencySubstitutions subs ->
projectSubstitutions.each { k,v ->
subs.substitute(subs.module(k)).with(subs.project(v))
Expand Down Expand Up @@ -336,7 +337,7 @@ gradle.projectsEvaluated {
if (tasks.findByPath('test') != null && tasks.findByPath('integTest') != null) {
integTest.mustRunAfter test
}
configurations.all { Configuration configuration ->
configurations.matching { it.canBeResolved }.all { Configuration configuration ->
dependencies.all { Dependency dep ->
Project upstreamProject = dependencyToProject(dep)
if (upstreamProject != null) {
Expand Down Expand Up @@ -617,7 +618,3 @@ allprojects {
}
}
}




34 changes: 3 additions & 31 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,37 +69,10 @@ processResources {
if (JavaVersion.current() < JavaVersion.VERSION_11) {
throw new GradleException('At least Java 11 is required to build elasticsearch gradle tools')
}
// Gradle 4.10 does not support setting this to 11 yet
targetCompatibility = "10"
sourceCompatibility = "10"

// We have a few classes that need to be compiled for older java versions because these are used to run checks against
// those
sourceSets {
minimumRuntime {
// We only want Java here, but the Groovy doesn't configure javadoc correctly if we don't define this as groovy
groovy {
srcDirs = ['src/main/minimumRuntime']
}
}
}
compileMinimumRuntimeGroovy {
targetCompatibility = 8
sourceCompatibility = 8
}
dependencies {
if (project.ext.has("isEclipse") == false || project.ext.isEclipse == false) {
// eclipse is confused if this is set explicitly
compile sourceSets.minimumRuntime.output
}
minimumRuntimeCompile "junit:junit:${props.getProperty('junit')}"
minimumRuntimeCompile localGroovy()
minimumRuntimeCompile gradleApi()
}
jar {
from sourceSets.minimumRuntime.output
}

// Keep compatibility with Java 8 for external users of build-tools that haven't migrated to Java 11
targetCompatibility = '8'
sourceCompatibility = '8'

/*****************************************************************************
* Dependencies used by the entire build *
Expand Down Expand Up @@ -164,7 +137,6 @@ if (project != rootProject) {
dependenciesInfo.enabled = false
forbiddenApisMain.enabled = false
forbiddenApisTest.enabled = false
forbiddenApisMinimumRuntime.enabled = false
jarHell.enabled = false
thirdPartyAudit.enabled = false

Expand Down
737 changes: 270 additions & 467 deletions buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import org.elasticsearch.gradle.test.RestIntegTestTask
import org.elasticsearch.gradle.test.RunTask
import org.elasticsearch.gradle.testclusters.TestClustersPlugin
import org.gradle.api.InvalidUserDataException
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.publish.maven.MavenPublication
Expand All @@ -43,13 +44,13 @@ import java.util.regex.Pattern
/**
* Encapsulates build configuration for an Elasticsearch plugin.
*/
class PluginBuildPlugin extends BuildPlugin {
class PluginBuildPlugin implements Plugin<Project> {

public static final String PLUGIN_EXTENSION_NAME = 'esplugin'

@Override
void apply(Project project) {
super.apply(project)
project.pluginManager.apply(BuildPlugin)

PluginPropertiesExtension extension = project.extensions.create(PLUGIN_EXTENSION_NAME, PluginPropertiesExtension, project)
configureDependencies(project)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,31 +118,32 @@ class PrecommitTasks {
}

private static Task configureThirdPartyAudit(Project project) {
ThirdPartyAuditTask thirdPartyAuditTask = project.tasks.create('thirdPartyAudit', ThirdPartyAuditTask.class)
ExportElasticsearchBuildResourcesTask buildResources = project.tasks.getByName('buildResources')
thirdPartyAuditTask.configure {
dependsOn(buildResources)
signatureFile = buildResources.copy("forbidden/third-party-audit.txt")
javaHome = project.runtimeJavaHome
targetCompatibility = project.runtimeJavaVersion
return project.tasks.create('thirdPartyAudit', ThirdPartyAuditTask.class) { task ->
task.dependsOn(buildResources)
task.signatureFile = buildResources.copy("forbidden/third-party-audit.txt")
task.javaHome = project.runtimeJavaHome
task.targetCompatibility.set(project.provider({ project.runtimeJavaVersion }))
}
return thirdPartyAuditTask
}

private static Task configureForbiddenApisCli(Project project) {
project.pluginManager.apply(ForbiddenApisPlugin)
ExportElasticsearchBuildResourcesTask buildResources = project.tasks.getByName('buildResources')
project.tasks.withType(CheckForbiddenApis) {
dependsOn(buildResources)
targetCompatibility = project.runtimeJavaVersion.getMajorVersion()
if (project.runtimeJavaVersion > JavaVersion.VERSION_11) {
doLast {
project.logger.info(
"Forbidden APIs does not support java version past 11. Will use the signatures from 11 for ",
project.runtimeJavaVersion
)
doFirst {
// we need to defer this configuration since we don't know the runtime java version until execution time
targetCompatibility = project.runtimeJavaVersion.getMajorVersion()
if (project.runtimeJavaVersion > JavaVersion.VERSION_11) {
doLast {
project.logger.info(
"Forbidden APIs does not support java version past 11. Will use the signatures from 11 for ",
project.runtimeJavaVersion
)
}
targetCompatibility = JavaVersion.VERSION_11.getMajorVersion()
}
targetCompatibility = JavaVersion.VERSION_11.getMajorVersion()
}
bundledSignatures = [
"jdk-unsafe", "jdk-deprecated", "jdk-non-portable", "jdk-system-out"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,6 @@ class ClusterFormationTasks {
// its run after plugins have been installed, as the extra config files may belong to plugins
setup = configureExtraConfigFilesTask(taskName(prefix, node, 'extraConfig'), project, setup, node)

// If the node runs in a FIPS 140-2 JVM, the BCFKS default keystore will be password protected
if (project.inFipsJvm){
node.config.systemProperties.put('javax.net.ssl.trustStorePassword', 'password')
node.config.systemProperties.put('javax.net.ssl.keyStorePassword', 'password')
}

// extra setup commands
for (Map.Entry<String, Object[]> command : node.config.setupCommands.entrySet()) {
// the first argument is the actual script name, relative to home
Expand Down Expand Up @@ -402,16 +396,17 @@ class ClusterFormationTasks {
if (node.nodeVersion.major >= 7) {
esConfig['indices.breaker.total.use_real_memory'] = false
}
for (Map.Entry<String, Object> setting : node.config.settings) {
if (setting.value == null) {
esConfig.remove(setting.key)
} else {
esConfig.put(setting.key, setting.value)
}
}

Task writeConfig = project.tasks.create(name: name, type: DefaultTask, dependsOn: setup)
writeConfig.doFirst {
for (Map.Entry<String, Object> setting : node.config.settings) {
if (setting.value == null) {
esConfig.remove(setting.key)
} else {
esConfig.put(setting.key, setting.value)
}
}

esConfig = configFilter.call(esConfig)
File configFile = new File(node.pathConf, 'elasticsearch.yml')
logger.info("Configuring ${configFile}")
Expand Down Expand Up @@ -732,6 +727,12 @@ class ClusterFormationTasks {
}
start.doLast(elasticsearchRunner)
start.doFirst {
// If the node runs in a FIPS 140-2 JVM, the BCFKS default keystore will be password protected
if (project.inFipsJvm){
node.config.systemProperties.put('javax.net.ssl.trustStorePassword', 'password')
node.config.systemProperties.put('javax.net.ssl.keyStorePassword', 'password')
}

// Configure ES JAVA OPTS - adds system properties, assertion flags, remote debug etc
List<String> esJavaOpts = [node.env.get('ES_JAVA_OPTS', '')]
String collectedSystemProperties = node.config.systemProperties.collect { key, value -> "-D${key}=${value}" }.join(" ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,52 +86,25 @@ class RestIntegTestTask extends DefaultTask {
runner.include('**/*IT.class')
runner.systemProperty('tests.rest.load_packaged', 'false')

/*
* We use lazy-evaluated strings in order to configure system properties whose value will not be known until
* execution time (e.g. cluster port numbers). Adding these via the normal DSL doesn't work as these get treated
* as task inputs and therefore Gradle attempts to snapshot them before/after task execution. This fails due
* to the GStrings containing references to non-serializable objects.
*
* We bypass this by instead passing this system properties vi a CommandLineArgumentProvider. This has the added
* side-effect that these properties are NOT treated as inputs, therefore they don't influence things like the
* build cache key or up to date checking.
*/
def nonInputProperties = new CommandLineArgumentProvider() {
private final Map<String, Object> systemProperties = [:]

void systemProperty(String key, Object value) {
systemProperties.put(key, value)
}

@Override
Iterable<String> asArguments() {
return systemProperties.collect { key, value ->
"-D${key}=${value.toString()}".toString()
}
}
}
runner.jvmArgumentProviders.add(nonInputProperties)
runner.ext.nonInputProperties = nonInputProperties

if (System.getProperty("tests.rest.cluster") == null) {
if (System.getProperty("tests.cluster") != null || System.getProperty("tests.clustername") != null) {
throw new IllegalArgumentException("tests.rest.cluster, tests.cluster, and tests.clustername must all be null or non-null")
}
if (usesTestclusters == true) {
ElasticsearchCluster cluster = project.testClusters."${name}"
nonInputProperties.systemProperty('tests.rest.cluster', "${-> cluster.allHttpSocketURI.join(",") }")
nonInputProperties.systemProperty('tests.cluster', "${-> cluster.transportPortURI }")
nonInputProperties.systemProperty('tests.clustername', "${-> cluster.getName() }")
runner.nonInputProperties.systemProperty('tests.rest.cluster', "${-> cluster.allHttpSocketURI.join(",") }")
runner.nonInputProperties.systemProperty('tests.cluster', "${-> cluster.transportPortURI }")
runner.nonInputProperties.systemProperty('tests.clustername', "${-> cluster.getName() }")
} else {
// we pass all nodes to the rest cluster to allow the clients to round-robin between them
// this is more realistic than just talking to a single node
nonInputProperties.systemProperty('tests.rest.cluster', "${-> nodes.collect { it.httpUri() }.join(",")}")
nonInputProperties.systemProperty('tests.config.dir', "${-> nodes[0].pathConf}")
runner.nonInputProperties.systemProperty('tests.rest.cluster', "${-> nodes.collect { it.httpUri() }.join(",")}")
runner.nonInputProperties.systemProperty('tests.config.dir', "${-> nodes[0].pathConf}")
// TODO: our "client" qa tests currently use the rest-test plugin. instead they should have their own plugin
// that sets up the test cluster and passes this transport uri instead of http uri. Until then, we pass
// both as separate sysprops
nonInputProperties.systemProperty('tests.cluster', "${-> nodes[0].transportUri()}")
nonInputProperties.systemProperty('tests.clustername', "${-> nodes[0].clusterName}")
runner.nonInputProperties.systemProperty('tests.cluster', "${-> nodes[0].transportUri()}")
runner.nonInputProperties.systemProperty('tests.clustername', "${-> nodes[0].clusterName}")

// dump errors and warnings from cluster log on failure
TaskExecutionAdapter logDumpListener = new TaskExecutionAdapter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ import org.elasticsearch.gradle.ExportElasticsearchBuildResourcesTask
import org.elasticsearch.gradle.VersionProperties
import org.elasticsearch.gradle.precommit.PrecommitTasks
import org.gradle.api.InvalidUserDataException
import org.gradle.api.JavaVersion
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.plugins.ExtraPropertiesExtension
import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.SourceSetContainer
import org.gradle.api.tasks.compile.JavaCompile
Expand All @@ -57,10 +60,13 @@ class StandaloneRestTestPlugin implements Plugin<Project> {
project.pluginManager.apply(JavaBasePlugin)

project.getTasks().create("buildResources", ExportElasticsearchBuildResourcesTask)
BuildPlugin.globalBuildInfo(project)
BuildPlugin.configureRepositories(project)
BuildPlugin.configureTestTasks(project)

ExtraPropertiesExtension ext = project.extensions.getByType(ExtraPropertiesExtension)
project.extensions.getByType(JavaPluginExtension).sourceCompatibility = ext.get('minimumRuntimeVersion') as JavaVersion
project.extensions.getByType(JavaPluginExtension).targetCompatibility = ext.get('minimumRuntimeVersion') as JavaVersion

// only setup tests to build
SourceSetContainer sourceSets = project.extensions.getByType(SourceSetContainer)
SourceSet testSourceSet = sourceSets.create('test')
Expand Down
Loading