1 Java Project Manager (1JPM), is a Maven/Gradle alternative with a twist. It's a single Java file itself, which should be edited by you to configure your project. Meaning instead of writing XML or Groovy/DSL, your build file is Java code too.
To build your project, simply drag-and-drop the JPM.java file
into your project, open a terminal and execute java JPM.java (Java 11 and above).
Java 8 to 10 and JDK notes
javac JPM.java && java -cp . JPMGood to know: - This repository functions as a template too - 1JPM is Maven based, thus great IDE support by default - 1JPM includes some extra plugins to increase runtime safety and provide additional features out of the box
public class JPM {
public static class ThisProject extends JPM.Project {
public ThisProject() throws IOException, InterruptedException {
this(null);
}
public ThisProject(List<String> args) throws IOException, InterruptedException {
// Override default configurations
this.groupId = "com.mycompany.myproject";
this.artifactId = "my-project";
this.version = "1.0.0";
this.mainClass = "com.mycompany.myproject.MyMainClass";
this.jarName = "my-project.jar";
this.fatJarName = "my-project-with-dependencies.jar";
// If there are duplicate dependencies with different versions force a specific version like so:
//forceImplementation("org.apache.commons:commons-lang3:3.12.0");
// Add dependencies
implementation("org.apache.commons:commons-lang3:3.12.0");
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.3");
// Add compiler arguments
addCompilerArg("-Xlint:unchecked");
addCompilerArg("-Xlint:deprecation");
// Add additional plugins
//putPlugin("org.codehaus.mojo:exec-maven-plugin:1.6.0", d -> {
// d.putConfiguration("mainClass", this.mainClass);
//});
// Execute build
if(args != null){
generatePom();
if(!args.contains("skipMaven"))
JPM.executeMaven("clean", "package");//, "-DskipTests");
// or JPM.executeMaven(args); if you prefer the CLI, like "java JPM.java clean package"
}
}
}
public static class ThirdPartyPlugins extends JPM.Plugins{
// Add third party plugins below, find them here: https://github.com/topics/1jpm-plugin?o=desc&s=updated
// (If you want to develop a plugin take a look at "JPM.AssemblyPlugin" class further below to get started)
}
// 1JPM version 3.0.3 by Osiris-Team: https://github.com/Osiris-Team/1JPM
// To upgrade JPM, replace everything below with its newer version
}
Above you can see the example configuration which runs the clean package tasks.
This compiles and creates a jar file from your code, and additionally creates the sources,
javadoc and with-dependencies jars.
See project.isAutoParentsAndChildren.
If true updates current pom, all parent and all child pom.xml
files with the respective parent details, adding seamless multi-module/project support.
This expects that the parent pom is always inside the parent directory, otherwise a performant search is not possible since the entire disk would need to be checked.
Add JPM.java to your root project directory and add JPM.portChildProjects(); before building.
This is going to download and copy the latest JPM.java file into all child projects it can find
in this directory, and also run it to generate an initial pom.xml for that child project.
The child projects name will be the same as its directory name.
A child project is detected
if a src/main/java folder structure exists, and the parent folder of src/ is then used as child project root.
Note that a child project is expected to be directly inside a subdirectory of this project.
Now project.isAutoParentsAndChildren will work properly, since all needed pom.xml files should exist.
Do you also need something like global variables across those projects?
Then the String val = $("key"); function might be of help to you,
since it can easily retrieve values for props defined in the nearest JPM.properties file.
GraalVM must be installed, then simply add JPM.plugins.add(NativeImagePlugin.get); before building.
The NativeImagePlugin in 1JPM is designed to integrate GraalVM's native image building capabilities into your Java project with minimal configuration. By default, it does the following:
Image Generation: It builds a native executable from your Java application using GraalVM. The generated executable is placed in the target directory.
Default Configuration:
imageName: Defaults to the project's artifactId.mainClass: Automatically determined from the project’s main class configuration.build-native execution: Compiles the project into a native image during the package phase.test-native execution: Compiles and runs tests as native images during the test phase.Basic Options: The plugin can be further configured with options like verbose output, additional buildArgs, or enabling debug information, but these are not set by default.
This setup allows you to seamlessly build native executables with GraalVM, leveraging its performance benefits and ahead-of-time (AOT) compilation, directly from your Maven build process.
For more details see this GraalVM article.
Simply add JPM.plugins.add(PackagerPlugin.get); before building.
With the default configuration, the PackagerPlugin in 1JPM:
This default setup is ideal for quickly packaging a Java application into a distributable format that includes everything needed to run the app. For more details see JavaPackager on GitHub.
Note that 1JPM is now using Maven under the hood, since the complexity as a fully independent build tool (see version 1.0.3) was too high for a single file. Besides, this gives us access to more features, a rich and mature plugin ecosystem, as well as great IDE compatibility. 1JPM will take care of generating the pom.xml, downloading the Maven-Wrapper, and then executing Maven as you can see above`.
A 1JPM plugin is basically a wrapper around a Maven plugin (its xml), providing easy access to its features, but can also be anything else to make building easier. These third-party plugins can be added simply by appending their Java code inside the ThirdPartyPlugins class. You can find a list here at #1jpm-plugin. (these must be written in Java 8 and not use external dependencies).
How many lines of relevant build code do we save compared to Maven? - 1JPM: 128 lines (see here) - Maven: 391 lines (see here)
Thus we write the same config with 263 lines less code (which is a 3x saving) when using 1JPM!
ThisProject class and your current build details files (pom.xml/build.gradle),
then prompting it something like: "Port my current Maven/Gradle project to the JPM build tool, by modifing the ThisProject class accordingly".
If you have additional plugins also send it an example plugin from within the JPM class.I am actively maintaining this repository, publishing new releases and working on its codebase for free, so if this project benefits you and/or your company consider donating a monthly amount you seem fit. Thank you!