如何将scala源附加到我的Maven jar? [英] How do I attach scala sources to my maven jar?
问题描述
我有一个包含Java和Scala混合代码的项目,该项目使用maven进行依赖和构建管理.我使用maven-source-plugin
构建了一个可以上传到我的Maven镜像的sources-jar,它对于 java 源(在src/main/java
中)工作得很好,但是对于 scala 源(在src/main/scala
中).
I have a project with mixed java and scala code, that uses maven for dependency and build management. I use the maven-source-plugin
to build a sources-jar that gets uploaded to my maven mirror, which works well for the java sources (in src/main/java
), but not for the scala sources (in src/main/scala
).
在scala-maven-plugin
网页上找不到任何帮助,但我可能错过了一些东西.无法在罐子中附加scala源吗?
I didn't find any help on the scala-maven-plugin
webpage, but I may have missed out on something. Is it not possible to attach scala sources in the jar?
我应该注意,类文件都在那里,因此取决于库的工作情况,只是缺少了scala源.
I should note that the class files are all there, so depending on the library works fine, it's just that the scala sources are missing.
推荐答案
我遇到了类似的问题;我加了maven-source-plugin
的罚款,但看到了
I had a similar problem; I'd added the maven-source-plugin
fine, but was seeing
[INFO] --- maven-source-plugin:3.0.0:jar (attach-sources) @ foo-bar ---
[INFO] No sources in project. Archive not created.
当我编译我的Scala项目时.
when I compiled my Scala project.
要解决此问题,我在scala-maven-plugin
配置中添加了add-source
目标,例如:
To fix this, I added the add-source
goal to my scala-maven-plugin
config, eg:
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>compile</goal>
<goal>add-source</goal>
</goals>
</execution>
...
</executions>
...
</plugin>
这会将您的Scala源代码添加到pom中,从而使maven-source-plugin
查找源文件并将其放入源jar中.
This adds your Scala source to the pom, which in turn allows the maven-source-plugin
to find the source files and put them in a source jar.
另请参见 http://davidb.github.io/scala-maven-plugin/add-source-mojo.html
这篇关于如何将scala源附加到我的Maven jar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!