Skip to content

Project Options

Geert Bevin edited this page Oct 21, 2023 · 5 revisions

Your IDE or the BaseProject Javadoc (which Project and WebProject extend), will give you an overview of all the project options that are available to you.

Design decisions

Before you start customizing everything, it's worth going over a few design decisions.

As you saw before, your build file extends the Project class, meaning that it's the only entity that has access to the Project fields, which are protected.

public class MyappBuild extends Project {
    public MyappBuild() {
        pkg = "com.example";                  // the root Java package of your project
        name = "Myapp";                       // the name of your project
        mainClass = "com.example.MyappMain";  // the fully qualified main class of your project
        version = version(0,1,0);             // your project's version
    }
    // public static void main ...
}

Available options

This makes it very convenient and intuitive to simply assign values to the project options. Below is the current list of available Project fields for configuration:

// required
File workDirectory;     // The work directory of the project.
String pkg;             // The project's package.
String name;            // The project's name.
VersionNumber version;  // The project's version.
String mainClass;       // The project's main class.

// optional
List<Repository> repositories;  // The project's repositories for dependency resolution.
DependencyScopes dependencies;  // The project's dependencies.

Integer javaRelease;        // The project's Java release version for compilation.
String javaTool;            // The tool that is used for running the java main class.
String archiveBaseName;     // The base name that is used for creating archives.
String jarFileName;         // The filename to use for the main jar archive creation.
String sourcesJarFileName;  // The filename to use for the sources jar archive creation.
String javadocJarFileName;  // The filename to use for the javadoc jar archive creation.
String uberJarFileName;     // The filename to use for the uber jar archive creation.
String uberJarMainClass;    // The main class to run the UberJar with.
Boolean autoDownloadPurge;  // Enable/disable auto dependency download and purge.
Boolean downloadSources;    // Enable/disable sources artifact downloads.
Boolean downloadJavadoc;    // Enable/disable javadoc artifact downloads.

File srcDirectory;                        // The source code directory.
File srcBldDirectory;                     // The bld source code directory.
File srcBldJavaDirectory;                 // The bld java source code directory.
File srcBldResourcesDirectory;            // The bld resources source code directory.
File srcMainDirectory;                    // The main source code directory.
File srcMainJavaDirectory;                // The main java source code directory.
File srcMainResourcesDirectory;           // The main resources source code directory.
File srcMainResourcesTemplatesDirectory;  // The main template resources source code directory.
File srcTestDirectory;                    // The test source code directory.
File srcTestJavaDirectory;                // The test java source code directory.
File srcTestResourcesDirectory;           // The test resources source code directory.
File libDirectory;                        // The lib directory.
File libCompileDirectory;                 // The compile scope lib directory.
File libRuntimeDirectory;                 // The runtime scope lib directory.
File libStandaloneDirectory;              // The standalone scope lib directory.
File libTestDirectory;                    // The test scope lib directory.
File buildDirectory;                      // The build directory.
File buildBldDirectory;                   // The bld build directory.
File buildDistDirectory;                  // The dist build directory.
File buildJavadocDirectory;               // The javadoc build directory.    
File buildMainDirectory;                  // The main build directory.
File buildTemplatesDirectory;             // The templates build directory.
File buildTestDirectory;                  // The test build directory.

Now, if you look at the BaseProject Javadoc again and scroll down to the methods, you'll see that for each option field there's identically named method. Anything from outside your project class will be using those methods to access these options, and if any of the optional ones aren't filled in, bld will provide a meaningful default value.

The optional methods for the directories are also using a smart hierarchical default behavior. For instance, if you set srcDirectory() to a particular path, then any of the sub-directories srcBldDirector(), srcMainDirectory(), ... will automatically adapt unless you provide a different option for those too.

Override options methods

Since any bld operation uses your project options through the methods of your build class, another customization option is to override the Project methods.

This is especially useful for the methods below that collect their entries dynamically at runtime.

List<File> mainSourceFiles();         // List all the main Java source files.
List<File> testSourceFiles();         // List all the test Java source files.

List<File> compileClasspathJars();    // Jar files in the compile scope classpath.
List<File> runtimeClasspathJars();    // Jar files in the runtime scope classpath.
List<File> standaloneClasspathJars(); // Jar files in the standalone scope classpath.
List<File> testClasspathJars();       // Jar files in the test scope classpath.

List<String> compileMainClasspath();  // Classpath entries for compiling the main sources.
List<String> compileTestClasspath();  // Classpath entries for compiling the test sources.
List<String> runClasspath();          // Classpath entries for running the application.
List<String> testClasspath();         // Classpath entries for testing the application.

For instance, this is how you can add another entry to the run classpath:

public class MyappBuild extends Project {
    public MyappBuild() {
        // ...
    }

    @Override
    public List<String> runClasspath() {
        var classpath = super.runClasspath();
        classpath.add(new File("another/classpath/location").getAbsolutePath());
        return classpath;
    }
    // public static void main ...
}

Java and RIFE2/core powered

Don't forget, your bld project files benefit from all the power of Java and RIFE2/core. You can for instance extract logic out into classes with custom bld operations, or you can create specialized project classes that make it easy to apply common traits, or you can use the RIFE2 template engine to generate files during your build cycle, ... the possibilities are endless.


Next learn more about Team Setup

Clone this wiki locally