bld Tips & Tricks
-
You can use this code in your build file to generate the project's pom in the project's root directory:
@BuildCommand(value = "pom-root", summary = "Generates the POM file in the root directory") public void pomRoot() throws FileUtilsErrorException { PomBuilder.generateInto(publishOperation().fromProject(this).info(), dependencies(), new File(workDirectory, "pom.xml")); }
Putting the pom in the root directory can help with tools like Snyk, SonarCloud, etc. as they will treat your project as a Maven project.
-
Annotation processors are easy to use with bld. Generally, you'll just need to include processor as a dependency, for example:
public class ExampleBuild extends Project { public ExampleBuild() { // ... scope(provided) .include(dependency("com.example", "annotator", version(1, 0, 0))); } }
If the processor is generating source files, you can easily specify where they should be saved, using the
-s
javac option, for example:/** * Saves generated source files in the {@code build/generated} directory. */ @Override public void compile() throws Exception { var generated = new File(buildDirectory(), "generated"); var ignore = generated.mkdir(); compileOperation().compileOptions().addAll(List.of("-s", generated.getAbsolutePath())); super.compile(); }
To incorporate the generated source code into the source tree, add this directory as an additional source location in your IDE.