如何将jar依赖项添加到xtext maven build

时间:2018-01-01 13:21:01

标签: maven xtext maven-dependency-plugin

在我的xtext dsl项目中使用maven jar文件的正确方法是什么?

我试过的是:

  • 使用pom.xml项目的*.dsl文件中的maven-dependency-plugin.jar文件从maven存储库下载到./lib/目录中。这在构建过程中尽早完成:在maven validate phase
  • in MANIFEST.MF:将jar添加到类路径中:例如Bundle-ClassPath: ., lib/value-2.5.6-annotations.jar
  • build.properties中:将其添加到bin.includes

问题是,只有当我两次调用mvn install时,构建才有效。

第一次,.jar文件按预期(在构建过程的早期)下载到lib目录,但是构建失败,因为它无法解析{{1}中的类型}}。
当我再次运行jar file时(mvn install文件现在已经存在于构建之前的.jar目录中),它可以正常工作。

有任何想法如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

简短回答

由于Tycho

中存在错误,目前无法按预期工作

长答案

以下是我在lib项目中所做的工作(现在):

pom.xml文件

  1. 我使用maven-dependency-pluginmaven validate phase中的jar文件(尽可能早在构建中)下载到stripVersion=true目录。
  2. 请注意,我使用lib,因此value-annotations.jar目录中的文件称为value-2.5.6-annotations.jar(而不是pom.xml)。如果我以后想要更新版本,我只需要在generateXtext文件中的一个位置更新它。
  3. 还必须将jar文件指定为依赖项,因为否则dsl插件的用户无法构建项目:即xtext-gradle-pluginpom.xml任务将失败,因为它无法找到类在jar文件中。
  4. 相关的<project ...> <properties> <xtextVersion>2.13.0</xtextVersion> <immutablesVersion>2.5.6</immutablesVersion> ... </properties> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>3.0.2</version> <executions> <execution> <id>copy-libraries</id> <phase>validate</phase> <goals> <goal>copy</goal> </goals> <configuration> <artifactItems> <artifactItem> <groupId>org.immutables</groupId> <artifactId>value</artifactId> <version>${immutablesVersion}</version> <classifier>annotations</classifier> <outputDirectory>lib</outputDirectory> </artifactItem> </artifactItems> <stripVersion>true</stripVersion> </configuration> </execution> </executions> </plugin> ... </build> <dependencies> <dependency> <groupId>org.immutables</groupId> <artifactId>value</artifactId> <version>${immutablesVersion}</version> <classifier>annotations</classifier> </dependency> </dependencies> </project> 代码:

    Bundle-ClassPath

    META-INF / MANIFEST.MF文件

    1. 将jar文件添加到DslJvmModelInferrer.xtend,以便我们可以使用它:例如在Export-Package
    2. 将jar文件的包添加到xxx.dsl.tests,以便MANIFEST.MF项目
    3. 可以访问这些文件

      Bundle-ClassPath: ., lib/value-annotations.jar Export-Package: xxx.xtext, ... xxx.xtext.validation, org.immutables.value 的相关部分:

      bin.includes

      build.properties文件

      将jar文件添加到target,以便将其复制到生成的jar文件(在bin.includes=model/generated/,\ .,\ META-INF/,\ lib/value-annotations.jar,\ plugin.xml 目录中):

      mvn verify

      构建

      现在构建工作在 Eclipse

      命令行(以及我的持续集成服务器脚本中),我必须执行两次maven(因为提到的错误):

      • mvn install(下载广告罐)
      • url1 <- "http://atla.avatarspirit.net/transcripts.php?num=120" webpage <- read_html(url1) webpage %>% html_nodes("b") %>% html_text()
相关问题