4

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.

dbf
  • 6,399
  • 2
  • 38
  • 65
  • Why? What purpose does this file have? Why is it not in your repository? – khmarbaise Jul 12 '18 at 07:46
  • @khmarbaise is a schema file used by client and server application to generate classes. So it is in some separate repo (not client or server). – dbf Jul 12 '18 at 08:05
  • 2
    Best would be to create a separate project which contains the schema file and generates the classes and make in the end a consumable jar file..... – khmarbaise Jul 12 '18 at 08:07
  • We generate for java and c#, so would like to share only schema and generate inside server or client apps – dbf Jul 12 '18 at 08:16

1 Answers1

1

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:git@github.com: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.

Slava Medvediev
  • 1,431
  • 19
  • 35