简体   繁体   English

我的scala-maven-plugin与多模块项目的配置不允许我在子目录中执行'mvn compile'

[英]my configuration of scala-maven-plugin with multi-module project doesn't let me do 'mvn compile' in a sub directory

We are using the scala-maven-plugin for our mixed Java/Scala project. 我们正在为我们的混合Java / Scala项目使用scala-maven-plugin。 Works nicely in general, but we have found that with a multi-module project we can't figure out how to do a'mvn compile' in a subdirectory. 一般来说工作得很好,但是我们发现使用多模块项目我们无法弄清楚如何在子目录中执行'mvn compile'。

I am unable to post my full source code to IP restrictions, but in my search for other projects that might have solved this issue I only managed to come up with other projects with the exact same problem. 我无法将我的完整源代码发布到IP限制,但在我搜索可能已解决此问题的其他项目时,我只能设法出现具有完全相同问题的其他项目。 Here is one for example: https://github.com/buildlackey/scala-multimodule-sample-project.git 这是一个例子: https//github.com/buildlackey/scala-multimodule-sample-project.git

The above project has three submodules beneath the directory that holds the root pom.xml: cats , dogs and web-application . 上面的项目在目录下面有三个子模块,它们包含根pom.xml: catsdogsweb-application If you git clone the above url, then cd to 'scala-multimodule-sample-project', you will see it build. 如果你git克隆上面的url,然后cd到'scala-multimodule-sample-project',你会看到它构建。 Now if I cd into the sub-module 'dogs' and do a 'mvn compile', I see the message: 现在如果我进入子模块'dogs'并进行'mvn compile',我会看到以下消息:

[INFO] No sources to compile

But there are sources to compile ! 但是有来源可以编译! The plugin is just not finding them. 该插件只是找不到它们。

This is the same thing that happens on my multi-module project. 这与我的多模块项目中发生的情况相同。 I can't post the whole source for our stuff.. But here is the relevant configuration from our top level pom.xml : 我不能发布我们的东西的整个源..但这里是我们的顶级pom.xml的相关配置:

<build>
    <sourceDirectory>${basedir}/src/main/scala</sourceDirectory>
    <testSourceDirectory>${basedir}/src/test/scala</testSourceDirectory>

  <!-- Compiling scala code -->
        <plugin>
          <!-- see http://davidb.github.com/scala-maven-plugin -->
          <groupId>net.alchim31.maven</groupId>
      <artifactId>scala-maven-plugin</artifactId>
      <version>3.2.2</version>
      <executions>
        <execution>
          <id>scala-compile</id>
          <phase>process-resources</phase>
          <goals>
            <goal>add-source</goal>
            <goal>compile</goal>
          </goals>
        </execution>
        <execution>
          <id>scala-test-compile</id>
          <phase>process-test-resources</phase>
          <goals>
            <goal>testCompile</goal>
          </goals>
        </execution>
      </executions>
    </plugin>

According to the documentation for the plug-in ( http://davidb.github.io/scala-maven-plugin/add-source-mojo.html ) there are are optional parameters that can be passed to the add-source goal: namely, sourceDir and testSourceDir 根据插件的文档( http://davidb.github.io/scala-maven-plugin/add-source-mojo.html ),可以将可选参数传递给add-source目标:即sourceDirtestSourceDir

However, I could not figure out how to pass these. 但是,我无法弄清楚如何通过这些。 Maybe those parameters are the key to success here ? 也许这些参数是成功的关键?

Finally, one kind of silly work-around that proved successful is to copy the same configuration for scala-maven-plugin into each submodule directory where I want to do a compile restricted to that submodule. 最后,证明成功的一种愚蠢的解决方法是将scala-maven-plugin的相同配置复制到每个子模块目录中,我想在那里进行限制到该子模块的编译。 Obviously this is a non-DRY, undesirable approach. 显然,这是一种非干燥的,不受欢迎的方法。

I'd be most grateful if anyone could suggest a good solution. 如果有人能提出一个好的解决方案,我将非常感激。

Thanks ! 谢谢 !

I uploaded a working sample at https://github.com/davidB/scala-maven-plugin/tree/master/samples/prj_multi_modules 我在https://github.com/davidB/scala-maven-plugin/tree/master/samples/prj_multi_modules上传了一份工作样本

The duplicate solution is the common usage. 重复的解决方案是常见的用法。

The DRY alternative is to declare the configuration of the plugin in the <pluginManagement> section, then add under <build><plugins><plugin> the groupId + artifactId for project(s) where you want to enable the plugin. DRY的替代方法是在<pluginManagement>部分声明插件的配置,然后在<build><plugins><plugin>下添加要启用插件的项目的groupId + artifactId。 You can add it into modules'pom.xml or into parent's pom.xml inherited by every modules. 您可以将它添加到modules'pom.xml或每个模块继承的父级pom.xml中。 You could also use <dependencyManagement> to avoid duplicate dependency's version. 您还可以使用<dependencyManagement>来避免重复依赖项的版本。

The addSource is to register additional source directory and expose it for IDE and other plugins. addSource是注册其他源目录并为IDE和其他插件公开它。

I think you have wrong value for sourceDir in your scala-multimodule-sample-project pom.xml file. 我认为你的scala-multimodule-sample-project pom.xml文件中的sourceDir值有错误。

I change sourceDir to the src/main/scala and after mvn compile I have the following output: 我将sourceDir更改为src / main / scala,并在mvn编译后输出以下内容:

...
[INFO] skip non existing resourceDirectory /home/grzesiek/dev/project/temp/scala-multimodule-sample-project/cats/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ cats ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-scala-plugin:2.15.2:compile (default) @ cats ---
[INFO] Checking for multiple versions of scala
[INFO] includes = [**/*.java,**/*.scala,]
[INFO] excludes = []
[INFO] /home/grzesiek/dev/project/temp/scala-multimodule-sample-project/cats/src/main/scala:-1: info: compiling
[INFO] Compiling 1 source files to /home/grzesiek/dev/project/temp/scala-multimodule-sample-project/cats/target/classes at 1453711735781
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM