forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Make
QuarkusBuild
not pollute Gradle's build cache
TODO: find a way to allow caching "large" uber-jars and native runnables (for those who want that) * Removes the huge `lib/` folder from the output-directory of the `QuarkusBuild` task to reduce the size of the cache entity in Gradle's build cache. * Introduce a new `QuarkusBuildLibs` task to produce the `lib/` folder and its content. This task's "up-to-date" checks works, but it is intentionally not cacheable (it's huge). Re-creating the contents of the `lib/` folder is rather cheap and the dependency artifacts are mangaged by the local artifact repository or via the project's build artifacts (jars generated by other modules of the same build). * Introduce a new `QuarkusBuildFinish` task to combine the output of the "`lib/`-less" `QuarkusBuild` and the output of the `QuarkusBuildLibs` tasks, so the result is the same as before this change. Other, related changes: * The `QuarkusBuild` task intentionally removes outputs for other package types than the currently configured one. This makes up-to-date checks work across multiple package types. Other notes: * The task names `quarkusLibsBuild` and `quarkusFinishBuild` are intentionally "that way around". Letting the names of these tasks begin with `quarkusBuild...` could confuse users, who use abbreviated task names on the command line (for example `./gradlew qB` is automagically expanded to `./gradlew quarkusBuild`, which would become ambiguous with `quarkusBuildLibs` and `quarkusBuildFinish`). Relates to: quarkusio#30852
- Loading branch information
Showing
7 changed files
with
293 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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 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
71 changes: 71 additions & 0 deletions
71
...e/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusBuildFinish.java
This file contains 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,71 @@ | ||
package io.quarkus.gradle.tasks; | ||
|
||
import java.io.File; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.gradle.api.file.FileSystemOperations; | ||
import org.gradle.api.tasks.Input; | ||
import org.gradle.api.tasks.OutputDirectory; | ||
import org.gradle.api.tasks.OutputFile; | ||
import org.gradle.api.tasks.TaskAction; | ||
|
||
/** | ||
* Finalizes the build of a Quarkus app, combining the outputs of {@link QuarkusBuild} and {@link QuarkusBuildLibs}. | ||
* | ||
* <p> | ||
* This task is required to "properly" cache the output of {@link QuarkusBuild} | ||
*/ | ||
public abstract class QuarkusBuildFinish extends QuarkusTask { | ||
|
||
public static final String QUARKUS_ARTIFACT_PROPERTIES = "quarkus-artifact.properties"; | ||
|
||
@Inject | ||
public QuarkusBuildFinish() { | ||
super("Finalize the Quarkus application build, prefer the 'quarkusBuild' task"); | ||
} | ||
|
||
@Inject | ||
public abstract FileSystemOperations getFileSystemOperations(); | ||
|
||
@Input | ||
public String getPackageType() { | ||
return quarkusBuild().getPackageType(); | ||
} | ||
|
||
@OutputDirectory | ||
public File getFastJar() { | ||
return quarkusBuild().getFastJar(); | ||
} | ||
|
||
@OutputFile | ||
public File getArtifactPropertiesFile() { | ||
return new File(getFastJar().getParentFile(), QUARKUS_ARTIFACT_PROPERTIES); | ||
} | ||
|
||
@TaskAction | ||
public void run() { | ||
File finalDir = getFastJar(); | ||
|
||
QuarkusBuild quarkusBuild = quarkusBuild(); | ||
if (!quarkusBuild.isFastJarLike()) { | ||
getLogger().info("Nothing to do for package type {}", quarkusBuild.getPackageType()); | ||
getFileSystemOperations().delete(delete -> delete.delete(finalDir)); | ||
return; | ||
} | ||
|
||
String outputDir = quarkusBuild.getOutputDirectory(); | ||
File appBuildDir = new File(quarkusBuild.getFastJarBuildDir(), outputDir); | ||
File libsBuildDir = new File(quarkusBuild.getLibsBuildDir(), outputDir); | ||
|
||
getLogger().info("Finalizing Quarkus build in {} from {} and {}", finalDir, appBuildDir, libsBuildDir); | ||
|
||
getFileSystemOperations().sync(sync -> { | ||
sync.into(finalDir); | ||
sync.from(appBuildDir, libsBuildDir); | ||
}); | ||
|
||
getFileSystemOperations().copy( | ||
copy -> copy.into(finalDir.getParent()).from(appBuildDir.getParent()).include(QUARKUS_ARTIFACT_PROPERTIES)); | ||
} | ||
} |
Oops, something went wrong.