Skip to content

Instantly share code, notes, and snippets.

@mateor
Last active June 8, 2016 17:48
Show Gist options
  • Save mateor/1249c8b1fc9cc10c9778a2921af19b54 to your computer and use it in GitHub Desktop.
Save mateor/1249c8b1fc9cc10c9778a2921af19b54 to your computer and use it in GitHub Desktop.
local publish with Pants

Local Publish

  1. Create a local directory and set it up to serve jars:

      mkdir -p ~/.m2-local/repository/
      python -m SimpleHTTPServer 8000
    
  2. Publish the jars to that location.

    • We use a (somewhat hacky) custom task called pom_publish but I assume you have a process.

      • ./pants publish.jar
      • maven
      • whatever.
    • FWIW, pom_publish looks like this:

        ./pants pom-publish --pom-publish-local='~/.m2-local/repository/' \
        --no-pom-publish-dryrun --pom-publish-version='0.0.99999' path/to/your/target
      
    • A pants publish.jar might look like:

        ./pants publish \
        --publish-jar-override=com.foo#bar_2.10=0.0.8 \
        --publish-jar-local=~/.m2-local/repository \
        --no-publish-jar-dryrun \
        --no-publish-jar-commit \
        src/main/scala/com/foo/bar:target_name 
      
    • One way or another, you need to see the jars under that directory:

      • It must be in a directory structure that ivy understands:
        • i.e. ~/.m2-local/repository/com/foo/bar/$rev/jar_name-rev.jar

Configure pants to resolve your local jars

  1. Tell your build-support/ivy/ivysettings.xml where to look for the jars.

    • Pants has chain repos in its ivysettings, which checks each resolver in order. This assumes you have a similar setup.

    • To avoid confusion, you should make the local resolver the first listed.

         <ibiblio name="localdev"
                   m2compatible="true"
                   usepoms="true"
                   root="http://localhost:8000"
                   pattern="[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]"
                   />
      
    • Note: this resolver may need to be adjusted to work with your publish semantics.

  2. Edit the rev of the jar's jar_library definition (almost certainly under 3rdparty) to match the version you passed on the command line.

  3. Run your usual pants command to consume the jar.

    • Pants will use your jars as long as you:
      • picked a unique version number
      • remembered to start the server in the directory
      • Have a pattern that matches your publish semantics
  4. Iterate as needed

    • Jar caching is very aggressive, so each time you rebuild the jar:

      • Bump the version passed to pom-publish
      • update the 3rdparty definition to match.

This is pretty odious to do over and over so try testing your jar as source as much as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment