zonkyio / embedded-postgres

Java embedded PostgreSQL component for testing
Apache License 2.0
341 stars 41 forks source link

Minimal package without a dependency on default binaries #106

Closed fwiesweg closed 1 year ago

fwiesweg commented 1 year ago

First of all, thanks a lot for your work, we've been relying on it for years for unit tests and local development builds. It's rock-solid and just makes live so much easier.

To my request: it'd be quite neat if it was possible to have an embeded-postgres-minimal package which does not depend on any set of default binaries, and to only add those which are really required to the mix. Our local CI stores the development builds for easier debugging (and some more complex testing down the line) and excluding the binaries we do not need (windows, alpine and darwin) reduced the JAR size by more than 60MB, which is quite a nice saving given the amount of automated builds we have.

It's possible to do that now by manually excluding the default dependencies (see below), but that depends on you not changing the default set of binaries in the future. Additionally, it'd allow to specify the exact required postgres version more concisely, without binaries of other versions hanging around in the class path which are not needed anyway and just lead to developer confusion.

Thank you very much for considering this; we'll keep using your package one way or the other ;-)

pom.xml so far

        <dependency>
            <groupId>io.zonky.test</groupId>
            <artifactId>embedded-postgres</artifactId>
            <version>${isatech.version.test.embeddedpg}</version>

            <exclusions>
                <exclusion>
                    <groupId>io.zonky.test.postgres</groupId>
                    <artifactId>embedded-postgres-binaries-linux-amd64-alpine</artifactId>
                </exclusion>

                <exclusion>
                    <groupId>io.zonky.test.postgres</groupId>
                    <artifactId>embedded-postgres-binaries-windows-amd64</artifactId>
                </exclusion>

                <exclusion>
                    <groupId>io.zonky.test.postgres</groupId>
                    <artifactId>embedded-postgres-binaries-darwin-amd64</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

Proposed pom.xml

        <dependency>
            <groupId>io.zonky.test</groupId>
            <artifactId>embedded-postgres-minimal</artifactId>
            <version>${isatech.version.test.embeddedpg}</version>
        </dependency>

        <dependency>
            <groupId>io.zonky.test</groupId>
            <artifactId>embedded-postgres-minimal</artifactId>
            <version>${isatech.version.test.embeddedpg.postgres}</version>
        </dependency>
tomix26 commented 1 year ago

Hi @fwiesweg,

Thanks for your kind words, glad to hear the project is making things easier 🙂

Regarding to your question, you can use the approach below to exclude all postgres binaries at once. Then you'll be safe even if the default set of binaries changes. I guess that's exactly what you're asking for, right? If so, it doesn't make sense to me to create an additional minimal package.

<dependency>
    <groupId>io.zonky.test</groupId>
    <artifactId>embedded-postgres</artifactId>
    <version>${isatech.version.test.embeddedpg}</version>
    <exclusions>
        <exclusion>
            <groupId>io.zonky.test.postgres</groupId>
            <artifactId>*</artifactId>
        </exclusion>
    </exclusions>
</dependency>
fwiesweg commented 1 year ago

Thanks, that looks amazing! It didn't even cross my mind that maven might support some kind of wildcard exclusions... Good to know.

I'll check it out first thing on Monday and let you know if that there's any issue with that approach.

fwiesweg commented 1 year ago

Works perfectly.