clojure-maven-plugin icon indicating copy to clipboard operation
clojure-maven-plugin copied to clipboard

All dependencies get packaged into jar

Open georgewfraser opened this issue 10 years ago • 8 comments

All the classes from dependencies end up in the packaged jar. This is different than the default of maven, and not what you want when you intend to publish the project to a maven repository and consume it in another project.

Minimal pom.xml that reproduces the error:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.fivetran</groupId>
    <artifactId>clojure-sandbox</artifactId>
    <version>1.0-SNAPSHOT</version>

    <packaging>clojure</packaging>

    <dependencies>
        <!-- Clojure language runtime -->
        <dependency>
            <groupId>org.clojure</groupId>
            <artifactId>clojure</artifactId>
            <version>1.6.0</version>
        </dependency>

        <!-- Fancy clojure JSON / Jackson wrapper -->
        <dependency>
            <groupId>cheshire</groupId>
            <artifactId>cheshire</artifactId>
            <version>5.3.1</version>
        </dependency>
    </dependencies>

    <build>
        <sourceDirectory>src</sourceDirectory>

        <testSourceDirectory>test</testSourceDirectory>

        <plugins>
            <!-- Teach maven about clojure -->
            <plugin>
                <groupId>com.theoryinpractise</groupId>
                <artifactId>clojure-maven-plugin</artifactId>
                <version>1.3.20</version>
                <extensions>true</extensions>

                <configuration>
                    <sourceDirectories>
                        <sourceDirectory>src</sourceDirectory>
                    </sourceDirectories>

                    <testSourceDirectories>
                        <testSourceDirectory>test</testSourceDirectory>
                    </testSourceDirectories>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

georgewfraser avatar Oct 27 '14 02:10 georgewfraser

This is a long long LONG standing bug/issue in clojure itself - it will write out ALL namespaces it compiles to the output directory ( http://dev.clojure.org/jira/browse/CLJ-322 ).

I thought we'd had a work-around inplace to delete the foreign namespaces but it looks like we don't. Shouldn't be hard to add tho. I wonder how other people get around this currently.

talios avatar Oct 28 '14 02:10 talios

Are there any suggested (i.e. tried and tested) workarounds for this behaviour?

anthcourtney avatar Nov 23 '14 02:11 anthcourtney

I keep meaning to put some time aside to update the plugin to have a "delete undiscovered namespaces" option which, after compilation will simply delete the any .class files it doesn't know about ( or more, to be a good citazen, compile to a temporary folder, and then copy only the .class files related to the discovered namespaces ).

As yet I've not had the time - pull requests welcome tho.

talios avatar Dec 08 '14 01:12 talios

Hopefully I can find some time to put aside whilst on Xmas holidays to look at this...

talios avatar Dec 18 '14 04:12 talios

Please note that for libraries, it is not recommended to AOT compile, anyway. For final projects, to the contrary, it may be interesting to have all classes, including dependencies, AOT compiled and included.

laurentpetit avatar May 15 '15 17:05 laurentpetit

However, there may still be the need to remove some namespace aot classes (for instance, some namespaces are so dynamic that they can't work if they're aot compiled, but they may be aot compiled transitively and must then be removed after the fact).

laurentpetit avatar May 15 '15 17:05 laurentpetit

I have this problem with cider-nrepl and CCW. I'm working on a patch for clojure-maven-plugin which does just the following: if a cleanAOTNamespaces configuration parameter is set to true - it's false by default -, then the <namespaces> regexes are used to remove undesired classes

laurentpetit avatar May 15 '15 17:05 laurentpetit

The PR has been published: #98

laurentpetit avatar May 15 '15 20:05 laurentpetit