Skip to content

Skip jar creation when no existing files will be included #510

@rcasta74

Description

@rcasta74

New feature, improvement proposal

Hello,

my understanding is that with skipIfEmpty=true will skip jar creation when src path does not exist or it does not contain any file.
It would be usefull if the above option could be used to skip jar creation also when no files will be included.

example.zip

In the attached example i have create the following possible use case:

example
├── module1
│   ├── pom.xml
│   └── src
│       ├── main
│       │   └── java
│       │       └── my
│       │           └── org
│       │               └── app1
│       │                   └── App1.java
│       └── test
│           └── java
│               └── my
│                   └── org
│                       └── app1
│                           ├── App1Test.java
│                           └── junit
│                               ├── MyExtension.java
│                               └── MyExtensionTest.java
├── module2
│   ├── pom.xml
│   └── src
│       ├── main
│       │   └── java
│       │       └── my
│       │           └── org
│       │               └── app2
│       │                   └── App2.java
│       └── test
│           └── java
│               └── my
│                   └── org
│                       └── app2
│                           └── App2Test.java
└── pom.xml

where parent pom contains:

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>3.5.0</version>
        <executions>
          <execution>
            <configuration>
              <classifier>junit</classifier>
              <skipIfEmpty>true</skipIfEmpty>
              <includes>
                  <include>**/junit/*</include>
              </includes>
              <excludes>
                  <exclude>**/*Test.class</exclude>
              </excludes>
            </configuration>
            <goals>
              <goal>test-jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

In the above scenario I would expect that junit jar will be created only for app1, while now it is created also for app2 with only pom and manifest files

❯ unzip -l module2/target/app2-1.0-junit.jar
Archive:  module2/target/app2-1.0-junit.jar
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2025-12-18 13:13   META-INF/
       81  2025-12-18 13:13   META-INF/MANIFEST.MF
        0  2025-12-18 13:13   META-INF/maven/
        0  2025-12-18 13:13   META-INF/maven/my.org/
        0  2025-12-18 13:13   META-INF/maven/my.org/app2/
      515  2025-12-18 10:48   META-INF/maven/my.org/app2/pom.xml
       43  2025-12-18 13:13   META-INF/maven/my.org/app2/pom.properties
---------                     -------
      639                     7 files

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions