Skip to content

forceCreation has no effect when skipIfEmpty is true #560

Description

@elharo

Bug

When both skipIfEmpty=true and forceCreation=true are set, forceCreation has no effect. The execute() method checks skipIfEmpty first and returns early without calling createArchive(), even though the user explicitly requested forced creation.

Location

AbstractJarMojo.java:303-306:

public void execute() throws MojoException {
    if (skipIfEmpty && isEmpty(getClassesDirectory())) {
        getLog().info(String.format("Skipping packaging of the %s.", getType()));
    } else {
        ...
    }
}

Problem

If a user configures both skipIfEmpty=true and forceCreation=true, the intent is presumably: "skip if empty, unless force is requested." However, skipIfEmpty always takes priority. forceCreation is only evaluated inside createArchive() which is never reached when the content directory is empty.

The @Parameter documentation for forceCreation (lines 114-124) describes it as forcing recreation of the JAR even if inputs have not changed. A user might reasonably expect that forceCreation=true would override skipIfEmpty=true and still produce the JAR.

Suggested fix

The execute() method should only skip when both skipIfEmpty=true and forceCreation=false, i.e.:

if (skipIfEmpty && !forceCreation && isEmpty(getClassesDirectory())) {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions