Added saving source files to build/generated directory

This commit is contained in:
Erik C. Thauvin 2023-08-20 11:06:51 -07:00
parent 878e1033f1
commit a8d3d7a4ea

View file

@ -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.
*
* <ul style="list-style-type:none">
* <li>./bld run</li>
* <li>./bld runExample</li>
* </ul>
*/
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.
* <p>
* 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();
}
}