Project KBean¶
ProjectKBean
acts as a wrapper around a JkProject
to facilitate the building of JVM-based code hosted in a project structure.
This KBean provides core methods for fundamental build tasks, including compiling, testing, and packaging.
To work effectively with this KBean, it's helpful to have an overview of the capabilities offered by the JkProject
object.
Key Features - Resolves dependencies, compiles code, and runs tests. - Creates various types of JAR files out-of-the-box, including regular, fat, shaded, source, and Javadoc JARs. - Infers project versions from Git metadata. - Executes packaged JARs. - Displays dependency trees and project setups. - Scaffolds skeletons for new projects.
Additionally, ProjectKBean
serves as a central point of interaction for other KBeans, enabling them to access project details and extend or enhance the build process.
Example for getting information about source files:
import dev.jeka.core.api.project.JkProject;
import dev.jeka.core.tool.builtins.project.ProjectKBean;
class MyBuild extends KBean {
final JkProject project = load(ProjectKBean.class).project;
private List<Path> allSourceFiles;
protected void init() {
allSourceFiles = project.compilation.layout.resolveSources().getFiles();
...
}
}
Example taken from JeKa:
- Jacoco KBean:
A KBean that reads te underlying
JkProject
and modifies its testing behavior. - Sonarqube KBean:
A KBean that reads te underlying
JkProject
to extract information. - Protobuf KBean:
A KBean that adds a Proto-buffer code generation to the underlying
JkProject
.