Home > database >  Installing a jar file using Intellij run configuration
Installing a jar file using Intellij run configuration

Time:09-27

I'm trying to create a run configuration in Intellij where a single click will do the build process for the developer for a maven based project. In it, the configuration is as below:

  1. Build module1
  2. Build module2
  3. Start server

The process works fine, but there is an issue when I build module2. Module2 is dependent on a jar file which is generated in the target folder of the module1 and module2 expects this jar to be copied over to local repository(.m2 folder), but the jar is not copied to .m2 folder since the pom.xml of moudle1 consists of plugin to skip installation as below:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-install-plugin</artifactId>
    <version>2.4</version>
    <configuration>
        <skip>true</skip>
    </configuration>
</plugin>

Which doesn't let this jar to be copied to the .m2 folder. This configuration has been added as there is space limitation on server and these installation are not required on it.

So what I need to do is somehow copy the jar from target folder of the moudle1 to the .m2 folder. I tried

mvn install:install-file -Dfile={path/to/my/legacy.jar} -DgroupId=mygroupid -DartifactId=legacy.jar -Dversion=1.2.3 -Dpackaging=jar

My concern over this is that I have to mention the path to file and version in a static way. Is it possible to somehow access these properties from the pom.xml file? Also the target folder is inside the project structure only, so having the path up to project structure dynamically will be good, rest all can be hardcoded.

Or is there all together another way to copy the jar file?

I cannot modify the pom.xml as it is a legacy structure and any changes I can do are via a run configurations only.

CodePudding user response:

Your second module could depend on the generated jar by using the system scope. You can read more about it here: system scope. Basically you would need to set up a dependency in the pom of the second module towards the needed jar as following:

    <dependency>
        <groupId>com.your.groupId</groupId>
        <artifactId>your-aritfact</artifactId>
        <version>your-version</version>
        <scope>system</scope>
        <systemPath>path/to/my/legacy.jar</systemPath>
        <!-- you could also use maven project properties like ${project.basedir} to not hardcode the full path -->
    </dependency>

Please note that the system scope is deprecated however I don't know if there is a replacement for it nor when it will be removed.

CodePudding user response:

So I found a way to do it via maven command line which can be used in run configuration:

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

where all the variables such as project.groupId, project.version etc are defined in the pom.xml of module1 and I run this command on same module. This successfully installs jar generated to .m2 folder under correct artifact folder structure.

This way there is no static value in the command itself.

  • Related