Pre- and post-java builder with custom module type

In my plugin I have defined my own module type, and I want the following external build process for a single module:

  1. My pre-Java builder
  2. Java
  3. My post-Java builder


In other words, I want to do something before the Java files are compiled, compile the Java files, and then do something after that.

From this post and this reference I get that I should implement some ModuleLevelBuilders with the right BuilderCategory. I did that, and return then from my overridden BuilderService.createModuleLevelBuilders() method, whose BuilderService class is registered as a service. This seems to work, but only for normal Java projects. My ModuleLevelBuilder's build() method never gets called for modules of my custom module type. How can I get my ModuleLevelBuilders to be called with a custom module type?

Alternatively, I tried this: to implement a ModuleBasedTarget and ModuleBasedBuildTargetType, and use a TargetBuilder to execute my build. Its build() method gets called as expected, but I don't know how I can execute a Java build before executing my post-java TargetBuilder, and more importantly, execute my pre-Java TargetBuilder before the Java build.


Any help or pointers are greatly appreciated.

1 comment
Comment actions Permalink

I found the issue. I didn't have any source roots in my module, and I didn't depend on the Java builder in my BuildTarget.

Firstly, in my `ModuleBuilder`, I needed to add at least one source root.

ContentEntry contentEntry = doAddContentEntry(rootModel);
contentEntry.addSourceFolder("src", false);

And secondly, since I'm using my custom ModuleType, I need one of my BuildTargets to depend on Java, by adding this to the BuildTarget's computeDependencies() method:

final List<BuildTarget<?>> dependencies = new ArrayList<>();
dependencies.add(new ModuleBuildTarget(super.myModule, JavaModuleBuildTargetType.PRODUCTION));
return dependencies;

By overriding the `BuildTarget`'s `isCompiledBeforeModuleLevelBuilders()` method and ordering my dependencies correctly, I can control whether a TargetBuilder is executed before or after executing the Java builder.
0

Please sign in to leave a comment.