jarek1208 / jarjar

Automatically exported from code.google.com/p/jarjar
0 stars 0 forks source link

Feature request: Jarjar maven plugin #25

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Having a jarjar maven plugin would be great.
The plugin could be executed during the package phase instead of the jar
plugin.

Original issue reported on code.google.com by rudamet...@gmail.com on 5 Dec 2008 at 1:36

GoogleCodeExporter commented 8 years ago
I think it's possible to use maven-antrun-plugin to execute jarjar ant task

Original comment by Dmitry.Bedrin on 15 Jul 2009 at 2:30

GoogleCodeExporter commented 8 years ago
anybody have an example of using antrun?  I'm not an expert, if I eventually 
get it
to work, I'll try to post it here.

Original comment by fern...@gmail.com on 3 Sep 2009 at 5:38

GoogleCodeExporter commented 8 years ago
jarjar already contains a maven plugin - however it seems it's rarely used so 
the build has swallowed it.

I've attached a patch that fixes the build process and also adds another 
parameter to the jarjar-plugin that 
enables the user to configure the skipping the manifest file.

To use the maven plugin you need to install the jarjar-plugin (generated from 
source by *ant mojo*) into your 
local maven repository and then use it like:

    <build>
        <plugins>
            <plugin>
                <groupId>com.tonicsystems.jarjar</groupId>
                <artifactId>jarjar-plugin</artifactId>
                <version>1.0</version>

                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>jarjar</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <fromJar>target/agni-${pom.version}-distribution.jar</fromJar>
                    <toJar>target/agni-${pom.version}-distribution.jar</toJar>
                    <rulesFile>rules.txt</rulesFile>
                </configuration>
            </plugin>
        </plugins>
    </build>

The behaviour is exactly the same as calling the command line.

Original comment by michael....@googlemail.com on 17 Nov 2009 at 1:53

Attachments:

GoogleCodeExporter commented 8 years ago
@fernman: antrun sample:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <tasks>
                    <taskdef name="jarjar" 
classname="com.tonicsystems.jarjar.JarJarTask"/>
                    <jarjar destfile="${build.directory}/${build.finalName}-jar-with-
dependencies.jar"
                            update="true">
                        <!-- Replace "x.y.." with "<groupId>.repackaged.x.y..". -->
                        <rule pattern="javax.annotation.**" 
result="${groupId}.repackaged.@0"/>
                        ...
                    </jarjar>
                </tasks>
            </configuration>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>com.tonicsystems.jarjar</groupId>
            <artifactId>jarjar</artifactId>
            <version>1.0-rc8</version>
        </dependency>
    </dependencies>
</plugin> 

Samuel Le Berrigaud at Atlassian also came up with a Groovy-based JarJar plugin 
(http://docs.atlassian.com/jarjar-maven-plugin/jarjar-mojo.html), but I kept 
running 
up against errors when trying to get it to work. See also 
http://old.nabble.com/jarjar-td5642213.html#a19929775.

Original comment by sharedo...@gmail.com on 17 Dec 2009 at 2:15

GoogleCodeExporter commented 8 years ago
Here's what I've been using successfully for a while now. This automates 
everything needed to deploy a usable artifact (in terms of downloading jarjar, 
etc.). This example packages guava and commons-lang into a single jar and 
*-sources.jar, rewritten with package prefix. Filling in basic maven stuff 
(artifact id, etc.) is left out.

     <properties>
        <jarjar.version>1.1</jarjar.version>
        <commons-lang.version>2.5</commons-lang.version>
        <guava.version>r09</guava.version>
        <package.prefix>my.package.internal</package.prefix>
    </properties>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies-to-jarjar</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>commons-lang</groupId>
                                    <artifactId>commons-lang</artifactId>
                                    <version>${commons-lang.version}</version>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>commons-lang</groupId>
                                    <artifactId>commons-lang</artifactId>
                                    <version>${commons-lang.version}</version>
                                    <classifier>sources</classifier>
                                </artifactItem>

                                <artifactItem>
                                    <groupId>com.google.guava</groupId>
                                    <artifactId>guava</artifactId>
                                    <version>${guava.version}</version>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>com.google.guava</groupId>
                                    <artifactId>guava</artifactId>
                                    <version>${guava.version}</version>
                                    <classifier>sources</classifier>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>

                <dependencies>
                    <dependency>
                        <groupId>com.googlecode.jarjar</groupId>
                        <artifactId>jarjar</artifactId>
                        <version>${jarjar.version}</version>
                    </dependency>
                </dependencies>

                <executions>
                    <execution>
                        <id>jarjar</id>
                        <phase>package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <tasks>
                                <taskdef name="jarjar" classname="com.tonicsystems.jarjar.JarJarTask" classpathref="maven.compile.classpath" />
                                <jarjar destfile="${project.build.directory}/${project.build.finalName}.jar" update="true">
                                    <!-- commons-lang rewrite -->
                                    <zipfileset src="${project.build.directory}/dependency/commons-lang-${commons-lang.version}.jar" />
                                    <rule pattern="org.apache.**" result="${package.prefix}.apache.@1" />

                                    <!-- guava rewrite -->
                                    <zipfileset src="${project.build.directory}/dependency/guava-${guava.version}.jar" />
                                    <rule pattern="com.google.**" result="${package.prefix}.google.@1" />
                                </jarjar>

                                <jarjar destfile="${project.build.directory}/${project.build.finalName}-sources.jar" update="true">
                                    <!-- commons-lang rewrite -->
                                    <zipfileset src="${project.build.directory}/dependency/commons-lang-${commons-lang.version}-sources.jar" />
                                    <rule pattern="org.apache.**" result="${package.prefix}.apache.@1" />

                                    <!-- guava rewrite -->
                                    <zipfileset src="${project.build.directory}/dependency/guava-${guava.version}-sources.jar" />
                                    <rule pattern="com.google.**" result="${package.prefix}.google.@1" />
                                </jarjar>
                            </tasks>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.5</version>
                <executions>
                    <execution>
                        <id>attach-artifacts</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>${project.build.directory}/${project.build.finalName}-sources.jar</file>
                                    <type>jar</type>
                                    <classifier>sources</classifier>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

One minor annoyance with this setup is that the source jars don't get rewritten 
correctly - the imports don't get rewritten with the package prefix. It should 
be fixable with a bit of ant voodoo.

Original comment by james.r...@gmail.com on 14 Apr 2011 at 3:35

GoogleCodeExporter commented 8 years ago
FYI I'm having good luck using: http://sonatype.github.com/jarjar-maven-plugin

Original comment by eric.dalquist on 8 Jul 2011 at 4:46