2

I have a maven plugin and I'd like to configure it by providing a path to a file/directory which is inside a dependency jar.

Here is a sample of my maven projects pom.xml. It has a plugin with a dependency which has a property as part of its execution called templateDirectory. I would like to put a path here to the plugins dependency mylang-swagger-codegen to a file/directory inside of the dependency { Some path }/src/resources/api/

How can I get to this path? I understand references like ${project.basedir} work to get to the project. Is there a way I can reference to the dependency and inside the jar to get to the file / directory I want?

<plugin>
    <groupId>io.swagger</groupId>
        <artifactId>swagger-codegen-maven-plugin</artifactId>
        <version>2.4.19</version>
        <executions>
            <execution>
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>
                    <inputSpec>${project.basedir}/api/swagger.yaml</inputSpec>
                    
                    <language>myLang</language>
      

        <templateDirectory>    <!-- Path here to api.mustache -->      </templateDirectory>
                    



            </execution>
        </executions>

        <dependencies>
            <dependency>
                <groupId>io.swagger</groupId>
                <artifactId>mylang-swagger-codegen</artifactId>
                <version>1.0.0</version>
            </dependency>
        </dependencies>
    </plugin>
</plugins>
visc
  • 4,794
  • 6
  • 32
  • 58

1 Answers1

2

Jar files are built on .zip. Maybe a Maven plugin that unwraps dependencies can help with what you want to accomplish.

Take a look at this to unpack a specific artifact: https://maven.apache.org/plugins/maven-dependency-plugin/examples/unpacking-artifacts.html

Or this, to unpack the project dependencies: https://maven.apache.org/plugins/maven-dependency-plugin/examples/unpacking-project-dependencies.html

After running this plugin, you can access the path where you unpacked the jar. In the examples above, the plugin runs in the "package" phase of maven. If you want to change the order, take a look at the maven build phases: https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

schmidi000
  • 310
  • 3
  • 14
  • Is there a way to avoid this? So Jar can be interpreted as a compressed zip- but jars aren't compressed correct? – visc Mar 26 '21 at 20:41
  • As far as I know, jar files are compressed with standard ZIP compression. You can programmatically access files in a jar like this: https://stackoverflow.com/questions/5171957/access-file-in-jar-file I'm not sure if there is a better way in maven to do this, except for unpacking it first. – schmidi000 Mar 27 '21 at 11:26