Maven 2.x JAR Plugin

Don't create empty jars

Details

  • Type: Improvement Improvement
  • Status: Reopened Reopened
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: 2.0
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Number of attachments :
    2

Description

Creating empty jars is confusing, it should just print a warning

use case:
parent pom attaching test jar, some subprojects may not have tests, why create jars for them?

  1. MJAR-20.patch
    24/Jun/06 5:07 PM
    3 kB
    Jochen Wiedmann
  2. MJAR-20-02.patch
    30/Jul/08 5:01 AM
    13 kB
    Rodrigo Ruiz

Issue Links

Activity

Hide
Carlos Sanchez added a comment -

Another use case

parent pom attaching test jar, maven creates an empty test jar for that pom project

Show
Carlos Sanchez added a comment - Another use case parent pom attaching test jar, maven creates an empty test jar for that pom project
Hide
Jerome Lacoste added a comment -

I believe this to duplicate MJAR-27 which has a patch. Make sure that the patch cover all cases reported by Carlos in this issue.

Show
Jerome Lacoste added a comment - I believe this to duplicate MJAR-27 which has a patch. Make sure that the patch cover all cases reported by Carlos in this issue.
Hide
Mike Perham added a comment -

I don't see how MJAR-27 solves Carlos's usecase. The parent POM can mandate that test-jars are created for all child projects. If one of those child projects has no src/test/java code but has src/main/java code, it will get an empty test-jar even though it is a java module.

Show
Mike Perham added a comment - I don't see how MJAR-27 solves Carlos's usecase. The parent POM can mandate that test-jars are created for all child projects. If one of those child projects has no src/test/java code but has src/main/java code, it will get an empty test-jar even though it is a java module.
Hide
Jochen Wiedmann added a comment -

Currently the jar plugin checks, whether the directory being archived exists. If so, a warning is currently issued.

I suggest to introduce a property "createEmptyArchive", which defaults to false. If the property is set to true, then the plugins behaviour remains unchanged. Otherwise, no jar file is created. This is what the attached patch does.

If the directory does exist, one could check for files. I leave it to the patches reviewer to decide whether this makes sense. A performance penalty is not to be expected, because one can stop searching as soon as the first file is found.

Show
Jochen Wiedmann added a comment - Currently the jar plugin checks, whether the directory being archived exists. If so, a warning is currently issued. I suggest to introduce a property "createEmptyArchive", which defaults to false. If the property is set to true, then the plugins behaviour remains unchanged. Otherwise, no jar file is created. This is what the attached patch does. If the directory does exist, one could check for files. I leave it to the patches reviewer to decide whether this makes sense. A performance penalty is not to be expected, because one can stop searching as soon as the first file is found.
Hide
Carlos Sanchez added a comment -

I did'n add the option to create an empty jar because I don't see any reason for it

Show
Carlos Sanchez added a comment - I did'n add the option to create an empty jar because I don't see any reason for it
Hide
Brett Porter added a comment -

I have reverted r417029 as it caused a regression (integration tests 94, 89, 88, 85, 81, 77, 72, 43, 41, 30)

Caused by: org.apache.maven.artifact.installer.ArtifactInstallationException: Error installing artifact: File c:\home\brett\scm\maven\components\maven-core-it\it0094\test\target\classes does not exist
at org.apache.maven.artifact.installer.DefaultArtifactInstaller.install(DefaultArtifactInstaller.java:84)
at org.apache.maven.plugin.install.InstallMojo.execute(InstallMojo.java:104)
... 19 more
Caused by: java.io.IOException: File c:\home\brett\scm\maven\components\maven-core-it\it0094\test\target\classes does not exist
at org.codehaus.plexus.util.FileUtils.copyFile(FileUtils.java:798)
at org.apache.maven.artifact.installer.DefaultArtifactInstaller.install(DefaultArtifactInstaller.java:70)
... 20 more

Please reapply, create a test to replicate this issue, then fix the issue.

Show
Brett Porter added a comment - I have reverted r417029 as it caused a regression (integration tests 94, 89, 88, 85, 81, 77, 72, 43, 41, 30) Caused by: org.apache.maven.artifact.installer.ArtifactInstallationException: Error installing artifact: File c:\home\brett\scm\maven\components\maven-core-it\it0094\test\target\classes does not exist at org.apache.maven.artifact.installer.DefaultArtifactInstaller.install(DefaultArtifactInstaller.java:84) at org.apache.maven.plugin.install.InstallMojo.execute(InstallMojo.java:104) ... 19 more Caused by: java.io.IOException: File c:\home\brett\scm\maven\components\maven-core-it\it0094\test\target\classes does not exist at org.codehaus.plexus.util.FileUtils.copyFile(FileUtils.java:798) at org.apache.maven.artifact.installer.DefaultArtifactInstaller.install(DefaultArtifactInstaller.java:70) ... 20 more Please reapply, create a test to replicate this issue, then fix the issue.
Hide
Rodrigo Ruiz added a comment -

My two cents

IMHO, if there is no contents to put into the jar, the plugin should do nothing. I have followed this approach and made a modification in trunk (2.3-SNAPSHOT).

I have verified the modification does not break the current tests, and added two new integration tests for verifying the altered behaviour.

I have attached my modification in patch format (MJAR-20-02.patch). The patch includes the modification to AbstractJarMojo.java, and the new integration tests.

I hope this helps,
Rodrigo

Show
Rodrigo Ruiz added a comment - My two cents IMHO, if there is no contents to put into the jar, the plugin should do nothing. I have followed this approach and made a modification in trunk (2.3-SNAPSHOT). I have verified the modification does not break the current tests, and added two new integration tests for verifying the altered behaviour. I have attached my modification in patch format (MJAR-20-02.patch). The patch includes the modification to AbstractJarMojo.java, and the new integration tests. I hope this helps, Rodrigo
Hide
Paul Gier added a comment -

Rodrigo, I took a look at the patch, but the problem I see is what happens when you get to the install phase? If you try to run "install" with no jar file available the build will crash, this might need to be addressed in the maven install plugin. The other problem would be deploying to the repository. If you deploy a pom with packaging "jar" then it might cause problems in the dependency resolution if there is no jar there.

Show
Paul Gier added a comment - Rodrigo, I took a look at the patch, but the problem I see is what happens when you get to the install phase? If you try to run "install" with no jar file available the build will crash, this might need to be addressed in the maven install plugin. The other problem would be deploying to the repository. If you deploy a pom with packaging "jar" then it might cause problems in the dependency resolution if there is no jar there.
Hide
Rodrigo Ruiz added a comment -

Hi Paul,

My patch adds a configuration option "createEmptyArchive" that can be set to true for forcing the jar creation. I see two ways of preventing what you describe:

1. Set the property default value to true. This means keeping the current default behaviour, allowing the developer to modify it at will.
2. Forcing its value to true when the classifier is null (main jar). This means changing the body of the isCreateEmptyArchive() method to:

protected boolean isCreateEmptyArchive() { return createEmptyArchive || getClassifier() == null; }

I would prefer the second option, because I think this is what most people would expect as the default behaviour (no test jar if there are no tests).

Show
Rodrigo Ruiz added a comment - Hi Paul, My patch adds a configuration option "createEmptyArchive" that can be set to true for forcing the jar creation. I see two ways of preventing what you describe: 1. Set the property default value to true. This means keeping the current default behaviour, allowing the developer to modify it at will. 2. Forcing its value to true when the classifier is null (main jar). This means changing the body of the isCreateEmptyArchive() method to: protected boolean isCreateEmptyArchive() { return createEmptyArchive || getClassifier() == null; } I would prefer the second option, because I think this is what most people would expect as the default behaviour (no test jar if there are no tests).
Hide
Alexandre Navarro added a comment -

Some news of including this patch in the next release?

Alexandre

Show
Alexandre Navarro added a comment - Some news of including this patch in the next release? Alexandre
Hide
Maki Korb added a comment -

should the maven-source-plugin have a corresponding issue like this one?

Show
Maki Korb added a comment - should the maven-source-plugin have a corresponding issue like this one?

People

Vote (15)
Watch (10)

Dates

  • Created:
    Updated: