0

So previously I was trying to find a way to install jar file which is built in my project to the .m2 folder via run configuration support. Link for reference. My main concern then was to not keep any hard coded values in command and to pick most data from pom.xml file. This was achieved successfully, but now I have another problem.

In the project, I have 2 modules module1 and module2. When module1 is built, it generates 2 files a war file since it is a web based application and second one is jar file which is used to satisfy dependencies of other modules. The jar file is generated using

<attachClasses>true</attachClasses>

property set in the maven-war-plugin in pom.xml of module1. So if the module1 artifact id is set as module1-corp, then the jar file is named as module1-corp-classes.jar if the jar is installed using maven-install-plugin. But due to the legacy structure of the project, maven-install-plugin cannot be used and I have to use maven command line via Intellij run configurations to install this file. So the command I used is

mvn install:install-file -Dfile=${project.build.directory}/${project.build.finalName}.jar -DgroupId=${project.groupId} -DartifactId=${project.artifactId} -Dversion=${project.version} -Dpackaging=jar

This installs the jar file perfectly, only it doesn't append the classes part at the end of jar file. so my jar file is now installed as module1-corp.jar instead of module1-corp-classes.jar which is not working okay with modules which are dependent on it.

I suspect this is due to the way module1 dependency is accessed in module2 which is as follows:

    <dependency>
        <groupId>module1.groupid</groupId>
        <artifactId>module1.artifactId</artifactId>
        <version>${module1.version}</version>
        **<classifier>classes</classifier>**
    </dependency>

This code is in the module2 pom.xml. I believe the classifier part is what is causing the issue, but I cannot change this since it is a legacy project.

So in the end I have two options only

  1. Rename the jar while it is being installed via maven command line
  2. Some other way which can rename the jar via an Intellij run configuration.

I tried using following flag

mvn install:install-file -Djar.finalName=jarname

But this doesn't seem to work as expected.

Mirhawk
  • 205
  • 1
  • 3
  • 14

1 Answers1

0

The install maven plugin allows also to specify the classifier (see: here). So in your example the command would need to be changed to:

mvn install:install-file -Dfile=${project.build.directory}/${project.build.finalName}.jar -DgroupId=${project.groupId} -DartifactId=${project.artifactId} -Dversion=${project.version} -Dpackaging=jar -Dclassifier=classes
Piotr Michalczyk
  • 249
  • 1
  • 13