Search code examples
javamavenjarconfluenceatlassian-plugin-sdk

How to include libraries/dependencies when creating a jar file?


I created a Confluence plugin(A Java application) which has Maven on it and includes some dependencies in the pom.xml as follows: (It needs to use the Google Client Library)

<dependencies>
    <dependency>
        <groupId>com.google.apis</groupId>
        <artifactId>google-api-services-calendar</artifactId>
        <version>v3-rev254-1.22.0</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.google.api-client</groupId>
        <artifactId>google-api-client</artifactId>
        <version>1.22.0</version>
        <scope>compile</scope>
    </dependency>

    ..... Skip .....

</dependencies>

I also downloaded the Google Client Library and created a "libs" folder at the "src/main/resources/" path in this maven project to store them, and added them as jars in Eclipse as follows:

enter image description here

However, after executed "atlas-debug" to invoke a Confluence instance or "atlas-package" commands, the final exported jar file usually does not include the dependencies/libraries (I found this according to the failed jar file size, it is much smaller than the successful one).

How to make the library files really be included into the exported jar file every time I executed "atlas-debug" or "atlas-package" commands?


Solution

  • You can use the maven-assembly-plugin plugin that will package all your dependency in the jar. You can configure it in the plugins section under the build section in your pom.xml:

    <build>
    ...
        <plugins>
        ...
           <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>2.2.2</version>
                    <executions>
                        <execution>
                            <id>assembly</id>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                            <configuration>
                                <descriptorRefs>
                                    <descriptorRef>jar-with-dependencies</descriptorRef>
                                </descriptorRefs>
                                <archive>
                                </archive>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
        ...
        </plugins>
    ...
    </build>
    

    Remember that the dependency configured with <scope>provided</scope> won't be included in the jar.