Checkout file from another repo using maven-scm plugin

915 Views Asked by At

I have a java application that is in git repo RepoA and has a scm configuration set up for this repo for maven-release plugin etc. I want to fetch one file from another RepoB (it is fine to checkout the whole repo also because there is only 1 file there) and use it as a part of build step. How to do it with maven-scm plugin if scm section is already set up for RepoA?

Thanks.

1

There are 1 best solutions below

0
Slava Medvediev On BEST ANSWER

You can use a separate maven profile for this task.
Here's profile part from pom.xml, assuming that you want to fetch file foo/bar.txt from github repo github-user/some-repo:

<profile>
    <id>checkout-foo-bar</id>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-scm-plugin</artifactId>
                <version>1.11.2</version>
                <configuration>
                    <connectionUrl>scm:git:[email protected]:github-user/some-repo</connectionUrl>
                    <includes>foo/bar.txt</includes>
                </configuration>
            </plugin>
        </plugins>
    </build>
</profile>

Then run mvn scm:checkout -P checkout-foo-bar

Plugin first fetches all the files from repo and then removes ones that you don't need. This takes extra time, especially if the repo is huge.

I didn't find a way to setup output directory other than default target/checkout. But hopefully this working example can be a good starting point to solve a problem.