2

I work on a Maven project that need to copy mode than 10 GB of artifacts in a target repository from a maven local repository (after downloaded them).

In some cases (e.g. for tests), I'd like to replace this copy by a symlink creation in order to save few minutes.

My question is: Is there a way to ask to plugin maven-dependency-plugin goal copy-dependencies to create a symlink OR is there any maven plugin that can do it.

Nelson G.
  • 5,145
  • 4
  • 43
  • 54
  • You can change the path to the local repo, see http://stackoverflow.com/questions/9123004/maven-is-it-possible-to-override-location-of-local-repository-via-the-use-of-co – Tunaki Oct 10 '16 at 09:02
  • It doesn't help me: In step 2) (copy from my local repo to my target) I want to create a symlink do dependency instead of copy it. – Nelson G. Oct 10 '16 at 09:06
  • 1
    Why? You can point to the local repo having the dependencies. But if you want a symlink to the repo, you can create yourself. What is the issue? – Tunaki Oct 10 '16 at 09:08
  • I made a mistake: I would like create a symlink with the goal 'copy-dependencies' of plugin 'maven-dependency-plugin'. I will rephrase – Nelson G. Oct 10 '16 at 09:19
  • I'm still not sure I understand the requirement. Can you edit with your complete use-case and/or sample POM? `copy-dependencies` copy the project dependencies, i.e. the files of the artifacts you depend on in your project, into a specified directory. What is the relation with a symlink? – Tunaki Oct 10 '16 at 09:25
  • Step 2 is very long because I copy from my local repo to target more than 10GB. I'd like to replace this copy by a symlink creation to accelerate project build (more than 10m to copy more than 10GB) – Nelson G. Oct 10 '16 at 09:39
  • 1
    Why are you copying all those data in the first place? – Tunaki Oct 10 '16 at 09:41
  • All copied data are used to create an APT repo. But in my case, I performs post-processing on copied data for test purpose and a symlink would be enough. I'd like to replace copy by a symlink in order to save a few minutes – Nelson G. Oct 10 '16 at 09:52
  • @Nelson You'd better re-tag your question and ask about how to parametrize this "APT repo" for a custom classpath. Copying libraries out of the local repository is usually a deployment smell. – Little Santi Oct 10 '16 at 10:24

1 Answers1

2

The copy-dependencies goal cannot, to my knowledge, do this out of the box. However, you can use a shell script:

#!/bin/sh
outputDir=target/dependency
mkdir -p "$outputDir"
mvn dependency:resolve |
  grep ':\(compile\|runtime\)' | sed 's/\[INFO\] *//' |
while read gav
do
  case "$gav" in
    *:*:*:*:*:*) # G:A:P:C:V:S
      g="${gav%%:*}"; remain="${gav#*:}"
      a="${remain%%:*}"; remain="${remain#*:}"
      p="${remain%%:*}"; remain="${remain#*:}"
      c="${remain%%:*}"; remain="${remain#*:}"
      v="${remain%%:*}"
      s="${remain#*:}"
      ;;
    *:*:*:*:*) # G:A:P:V:S
      g="${gav%%:*}"; remain="${gav#*:}"
      a="${remain%%:*}"; remain="${remain#*:}"
      p="${remain%%:*}"; remain="${remain#*:}"
      c=""
      v="${remain%%:*}"
      s="${remain#*:}"
      ;;
  esac
  g=$(echo "$g" | sed 's/\./\//g')
  test -n "$c" && artName="$a-$v-$c" || artName="$a-$v"
  ln -s "$HOME/.m2/repository/$g/$a/$v/$artName.$p" "$outputDir"
done
ctrueden
  • 6,751
  • 3
  • 37
  • 69