Skip to content

Commit

Permalink
[Gradle] fix esql compile cacheability (#111651)
Browse files Browse the repository at this point in the history
- We use a JvmCommandlineprovider to reference the generated source folder and keep gradle cache happy
  • Loading branch information
breskeby authored Aug 7, 2024
1 parent cda8773 commit 741224f
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 148 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

package org.elasticsearch.gradle.internal.util;

import org.gradle.api.file.Directory;
import org.gradle.api.tasks.InputDirectory;
import org.gradle.api.tasks.PathSensitive;
import org.gradle.api.tasks.PathSensitivity;
import org.gradle.process.CommandLineArgumentProvider;

import java.util.Arrays;

public class SourceDirectoryCommandLineArgumentProvider implements CommandLineArgumentProvider {

private final Directory sourceDirectory;

public SourceDirectoryCommandLineArgumentProvider(Directory sourceDirectory) {
this.sourceDirectory = sourceDirectory;
}

public Iterable<String> asArguments() {
return Arrays.asList("-s", sourceDirectory.getAsFile().getAbsolutePath());
}

@InputDirectory
@PathSensitive(PathSensitivity.RELATIVE)
public Directory getSourceDirectory() {
return sourceDirectory;
}
}
3 changes: 2 additions & 1 deletion x-pack/plugin/esql/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import org.elasticsearch.gradle.internal.info.BuildParams
import org.elasticsearch.gradle.internal.precommit.CheckForbiddenApisTask;
import org.elasticsearch.gradle.internal.util.SourceDirectoryCommandLineArgumentProvider;

apply plugin: 'elasticsearch.internal-es-plugin'
apply plugin: 'elasticsearch.internal-cluster-test'
Expand Down Expand Up @@ -50,7 +51,7 @@ dependencies {
}

tasks.named("compileJava").configure {
options.compilerArgs.addAll(["-s", "$projectDir/src/main/generated"])
options.compilerArgumentProviders.add(new SourceDirectoryCommandLineArgumentProvider(project.layout.projectDirectory.dir("src/main/generated")))
// IntelliJ sticks generated files here and we can't stop it....
exclude { it.file.toString().contains("$projectDir/src/main/generated-src/generated") }
}
Expand Down
Loading

0 comments on commit 741224f

Please sign in to comment.