0

How should I configure maven parent pom to checkout code before Module list fails because the pom cannot be found.

It seems the maven's reactor test for a module's pom occurs before the generate-sources phase when scm checkouts the projects with the projects' pom.

How can I fix this ?

<modules>
  <module>target/mod-1</module>
  <module>target/mod-2</module>
</modules>

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-scm-plugin</artifactId>
      <version>1.9.4</version>
      <executions>
        <execution>
          <id>mod-1</id>
          <phase>generate-sources</phase>
          <configuration>
            <connectionUrl>${mod-1.url}</connectionUrl>
            <scmVersionType>${mod-1.versionType}</scmVersionType>
            <scmVersion>${mod-1.version}</scmVersion>
            <checkoutDirectory>${mod-1.directory}</checkoutDirectory>
          </configuration>
          <goals>
            <goal>checkout</goal>
          </goals>
        </execution>
        <execution>
          <id>mod-2</id>
          <phase>generate-sources</phase>
          <configuration>
            <connectionUrl>${mod-2.url}</connectionUrl>
            <scmVersionType>${mod-2.versionType}</scmVersionType>
            <scmVersion>${mod-2.version}</scmVersion>
            <checkoutDirectory>${mod-2.directory}</checkoutDirectory>
          </configuration>
          <goals>
            <goal>checkout</goal>
          </goals>
        </execution>
      </executions>

.....

</build>
garyM
  • 802
  • 2
  • 12
  • 29
  • Simple answer. That will not work, cause the pom's are read before anything within the pom's can be executed furthermore `target/mod-1` this can't be correct. I suppose it's only for demonstration cause the `target` folder is reserved for Maven?... – khmarbaise Mar 23 '19 at 22:07
  • Doesn't it look like that your path seemed to be the wrong path and you should change the structure of your repositories/project to either have separate project which will not being built together or make a single multi module build of it and have a single repository (git?)... – khmarbaise Mar 23 '19 at 22:10
  • the target/mod-1 is correct. The target folder is created by the scm plugin. – garyM Mar 23 '19 at 23:14
  • The reason for the pom is to control the build of independent modules into a single library. If I can't checkout and build a simple multi module library, maven is worthless. – garyM Mar 23 '19 at 23:17
  • 1
    The pom is the declarative definition of the build and it's dependencies. If we are talking about a multiple modules then it is called a multi module build which is within a single git repository and checkout at the same time. If you have a project which uses other libs it defines them simply as dependencies but does not build them. Maven is based on binary artifacts (consumed from Maven Central or an repository manager) not on source dependencies. – khmarbaise Mar 23 '19 at 23:25
  • Example: https://github.com/khmarbaise/javaee this results in a single EAR file this one https://github.com/khmarbaise/supose results in a single tar.gz file..? – khmarbaise Mar 23 '19 at 23:25
  • To me it sounds as you haven't yet understood the multi module concept? Maybe I'm wrong? – khmarbaise Mar 23 '19 at 23:25
  • @khmarbaise I understand the multi-module concept and have projects building via a parent. I have scm checking out multiple modules. I have multiple modules building once checked out. I don't have scm checking out multi-modules and building them. The reactor code and SCM documentation is very weak in this area. – garyM Mar 23 '19 at 23:46
  • Your setup looks wrong...make a single git repository which contains the multi module build and it can be build with a single command...? – khmarbaise Mar 23 '19 at 23:58
  • @khmarbaise yeah, I know the setup is wrong. The multi module build is not the problem, its the interaction between multi-module reactor and scm. More specifically, checking for pom before the checkout is complete. I'm looking for other plugins – garyM Mar 24 '19 at 00:29
  • @khmarbaise is right. You cannot check out modules during the build, check outs need to happen before the build. Your life will be much easier if everything is in the same SVN or git repository. – J Fabian Meier Mar 24 '19 at 09:52
  • @JF Meier Thanks for the feedback and advise. The sources are in different repositories and that's not changing. I'm wrangling the build tree in the am. This issue is a race condition between the multi-module reactor and the scm plugin. It either a: new requirement, a design oversight or the the evolution of the reactor from when the scm plugin was written – garyM Mar 25 '19 at 04:28
  • @garyM Having the sources in different repositories means that you need to check out all of them _before_ the build, not inside the Maven build. – J Fabian Meier Mar 25 '19 at 07:56
  • @JF Meier, Please look at the documentation on scm:checkout https://maven.apache.org/scm/maven-scm-plugin/checkout-mojo.html and checkout description in scm-release-plugin:perform http://maven.apache.org/maven-release/maven-release-plugin/examples/perform-release.html . These definitely checkout code and the scm works using the execute pattern (scm-release-plugin does not). However, they will not checkout using the module pattern. I was looking for a way to use the scm plugin with the module pattern – garyM Mar 25 '19 at 14:44
  • @garyM I am just trying to say that your approach is breaking expectations and that it is likely not to work. Instead, I would check out all the code from all relevant repositories and then start the Maven build. Why not just do that? – J Fabian Meier Mar 25 '19 at 14:51
  • @JF Meier, Thank you ! and I hear you loud and clear. I was pushing maven a bit further than what it can handle. I prefer clear case and sometimes expect other systems to have similar capabilities. I'm attempting to fully automate checkout and build from multiple repositories into a one executable file solution. This issue would not have been posted here if these limitations would be documented on the maven site – garyM Mar 25 '19 at 15:54

0 Answers0