From a8d3d7a4ea5165c2e0dd4dab71011863ac2c33e1 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Sun, 20 Aug 2023 11:06:51 -0700 Subject: [PATCH] Added saving source files to build/generated directory --- .../bld/java/com/example/ExampleBuild.java | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/examples/java/bld/src/bld/java/com/example/ExampleBuild.java b/examples/java/bld/src/bld/java/com/example/ExampleBuild.java index d00568c..7bf9e50 100644 --- a/examples/java/bld/src/bld/java/com/example/ExampleBuild.java +++ b/examples/java/bld/src/bld/java/com/example/ExampleBuild.java @@ -3,11 +3,20 @@ package com.example; import rife.bld.BuildCommand; import rife.bld.Project; +import java.io.File; import java.util.List; import static rife.bld.dependencies.Repository.*; import static rife.bld.dependencies.Scope.compile; +/** + * Example build. + * + * + */ public class ExampleBuild extends Project { public ExampleBuild() { pkg = "com.example"; @@ -20,16 +29,29 @@ public class ExampleBuild extends Project { repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL); - scope(compile) - .include(dependency("net.thauvin.erik", "semver", version(1, 2, 1, "SNAPSHOT"))); - } - - @BuildCommand(summary = "Run the example") - public void runExample() throws Exception { - runOperation().executeOnce(() -> runOperation().fromProject(this).mainClass("com.example.Example")); + scope(compile).include(dependency("net.thauvin.erik", "semver", version(1, 2, 1, "SNAPSHOT"))); } public static void main(String[] args) { new ExampleBuild().start(args); } + + /** + * Saves generated source files in the {@code build/generated} directory. + *

+ * To incorporate the generated source code into the source tree, add this directory as an additional source + * location in your IDE. + */ + @Override + public void compile() throws Exception { + var generated = new File(buildDirectory(), "generated"); + var ignore = generated.mkdir(); + this.compileOperation().compileOptions().addAll(List.of("-s", generated.getAbsolutePath())); + super.compile(); + } + + @BuildCommand(summary = "Run the example") + public void runExample() throws Exception { + runOperation().fromProject(this).mainClass("com.example.Example").execute(); + } }