我正在尝试使用xtend-maven-plugin和xtext-maven-plugin编译我的Maven构建中的xtext和xtend文件。但是,当尝试运行构建时,Maven在尝试解决依赖关系时似乎遇到了问题。我尝试将错误范围缩小到依赖项
<dependency>
<groupId>org.eclipse.xtext</groupId>
<artifactId>org.eclipse.xtext</artifactId>
<version>2.21.0</version>
</dependency>
当它试图解决某些传递依赖时,似乎出现了问题。堆栈跟踪为:
java.lang.NullPointerException
at java.util.Hashtable$Entry.setValue(Hashtable.java:1286)
at org.apache.maven.model.interpolation.StringVisitorModelInterpolator$ModelVisitor.visit(StringVisitorModelInterpolator.java:1429)
at org.apache.maven.model.interpolation.StringVisitorModelInterpolator$ModelVisitor.visit(StringVisitorModelInterpolator.java:1027)
at org.apache.maven.model.interpolation.StringVisitorModelInterpolator$ModelVisitor.visit(StringVisitorModelInterpolator.java:170)
at org.apache.maven.model.interpolation.StringVisitorModelInterpolator.interpolateModel(StringVisitorModelInterpolator.java:107)
at org.apache.maven.model.building.DefaultModelBuilder.interpolateModel(DefaultModelBuilder.java:789)
at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:393)
at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom(DefaultArtifactDescriptorReader.java:292)
at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.readArtifactDescriptor(DefaultArtifactDescriptorReader.java:171)
at org.eclipse.aether.internal.impl.collect.DefaultDependencyCollector.resolveCachedArtifactDescriptor(DefaultDependencyCollector.java:541)
at org.eclipse.aether.internal.impl.collect.DefaultDependencyCollector.getArtifactDescriptorResult(DefaultDependencyCollector.java:524)
at org.eclipse.aether.internal.impl.collect.DefaultDependencyCollector.processDependency(DefaultDependencyCollector.java:412)
at org.eclipse.aether.internal.impl.collect.DefaultDependencyCollector.processDependency(DefaultDependencyCollector.java:365)
at org.eclipse.aether.internal.impl.collect.DefaultDependencyCollector.process(DefaultDependencyCollector.java:352)
at org.eclipse.aether.internal.impl.collect.DefaultDependencyCollector.doRecurse(DefaultDependencyCollector.java:509)
at org.eclipse.aether.internal.impl.collect.DefaultDependencyCollector.processDependency(DefaultDependencyCollector.java:461)
at org.eclipse.aether.internal.impl.collect.DefaultDependencyCollector.processDependency(DefaultDependencyCollector.java:365)
at org.eclipse.aether.internal.impl.collect.DefaultDependencyCollector.process(DefaultDependencyCollector.java:352)
at org.eclipse.aether.internal.impl.collect.DefaultDependencyCollector.collectDependencies(DefaultDependencyCollector.java:254)
at org.eclipse.aether.internal.impl.DefaultRepositorySystem.collectDependencies(DefaultRepositorySystem.java:284)
at org.apache.maven.plugin.internal.DefaultPluginDependenciesResolver.resolveInternal(DefaultPluginDependenciesResolver.java:205)
at org.apache.maven.plugin.internal.DefaultPluginDependenciesResolver.resolve(DefaultPluginDependenciesResolver.java:152)
at org.apache.maven.plugin.internal.DefaultMavenPluginManager.createPluginRealm(DefaultMavenPluginManager.java:404)
at org.apache.maven.plugin.internal.DefaultMavenPluginManager.setupPluginRealm(DefaultMavenPluginManager.java:374)
at org.apache.maven.plugin.DefaultBuildPluginManager.getPluginRealm(DefaultBuildPluginManager.java:234)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:105)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:957)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
我尝试使用mvnDebug调试代码,但不幸的是StringVisitorModelInterpolator类不提供源代码。我可以看到一些变量:
我猜想inter
变量正在被插值,并且以某种方式变为null并传递给Entry对象,该对象随后引发异常。
不幸的是,我没有找到提供我需要编译的类的其他依赖项。 我不确定,但是这个问题可能与以下讨论有关:Link to maven Github pull request discussion
除了在GitHub上解决此问题的方法之外,还有其他解决方法吗?
谢谢。
答案 0 :(得分:0)
我碰巧在一个使用xtend和xtext的项目中工作。这是xtend-maven插件的配置:
<plugin><!--xtend-maven-plugin-->
<groupId>org.eclipse.xtend</groupId>
<artifactId>xtend-maven-plugin</artifactId>
<version>2.14.0</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
<maven.compiler.source>1.7</maven.compiler.source>
<jvmSettings>
<fork>true</fork>
<jvmArgs>
<jvmArg>-Xms100m</jvmArg>
<jvmArg>-Xmx500m</jvmArg>
<jvmArg>-XX:MaxPermSize=512m</jvmArg>
</jvmArgs>
</jvmSettings>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<!-- need to prefix by basedir to generate to currently built module -->
<outputDirectory>${basedir}/xtend-gen</outputDirectory>
</configuration>
</execution>
</executions>
<dependencies>
<!-- these dependencies are contributed in Eclipse by the "Xtend Library"
classpath container -->
<dependency>
<groupId>org.eclipse.xtend</groupId>
<artifactId>org.eclipse.xtend.lib</artifactId>
<version>2.14.0</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.common</artifactId>
<version>3.10.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.emf</groupId>
<artifactId>org.eclipse.emf.codegen</artifactId>
<version>2.11.0</version>
</dependency>
</dependencies>
</plugin>
希望这会有所帮助。我没有为您配置xtext-maven-plugin,我们使用exec-maven-plugin执行来运行MWE工作流以生成我们的xtext类。
自从您询问类路径以来,我的MWE工作流程如下:
var rootPath = ".."
var fileExtensions = "ext"
var projectName = "myProject"
var runtimeProject = "../${projectName}"
var languageName = "mylanguage"
var grammarURI = "platform:/resource/myProject/src/myPackage/myGrammar.xtext"
Workflow {
bean = StandaloneSetup {
scanClassPath = true
platformUri = "${runtimeProject}/.."
}
component = XtextGenerator {
configuration = {
project = StandardProjectConfig {
baseName = projectName
rootPath = rootPath
runtimeTest = {
enabled = true
}
eclipsePlugin = {
enabled = true
}
eclipsePluginTest = {
enabled = true
name = "${projectName}.tests"
}
createEclipseMetaData = true
}
code = {
encoding = "UTF-8"
fileHeader = "/*\n * generated by Xtext \${version}\n */"
}
}
language = XtextGeneratorLanguage {
name = languageName
grammarUri = grammarURI
referencedResource = protoBufGenModelPath
fileExtensions = fileExtensions
fragment = grammarAccess.GrammarAccessFragment2 {}
fragment = ecore.EMFGeneratorFragment2 {}
fragment = resourceFactory.ResourceFactoryFragment2 {}
fragment = parser.antlr.XtextAntlrGeneratorFragment2 {}
// An adapter to old fragment since support for this is not present in the latest versions.
fragment = org.eclipse.xtext.generator.adapter.FragmentAdapter {
fragment = org.eclipse.xtext.generator.parser.antlr.XtextAntlrUiGeneratorFragment {}
}
fragment = exporting.QualifiedNamesFragment2 {}
fragment = serializer.SerializerFragment2 {
generateStub = false
}
// An adapter to old fragment since support for this is not present in the latest versions.
fragment = org.eclipse.xtext.generator.adapter.FragmentAdapter {
fragment = org.eclipse.xtext.generator.formatting.FormatterFragment {
generateStub = false
}
}
fragment = ui.labeling.LabelProviderFragment2 {}
fragment = ui.outline.OutlineTreeProviderFragment2 {}
fragment = ui.outline.QuickOutlineFragment2 {}
fragment = ui.quickfix.QuickfixProviderFragment2 {}
fragment = ui.contentAssist.ContentAssistFragment2 {}
fragment = ui.refactoring.RefactorElementNameFragment2 {}
fragment = junit.JUnitFragment {}
}
}
}
然后我只需使用exec-maven-plugin在pom中调用它即可:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<killAfter>-1</killAfter>
<cleanupDaemonThreads>false</cleanupDaemonThreads>
<includeProjectDependencies>true</includeProjectDependencies>
<includePluginDependencies>true</includePluginDependencies>
<mainClass>org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher</mainClass>
<arguments>
<argument>file://${project.basedir}/src/myPackage/myGrammar.mwe2</argument>
<argument>-p</argument>
<argument>runtimeProject=plugins/${project.artifactId}</argument>
<argument>rootPath=plugins</argument>
</arguments>
<includeProjectDependencies>true</includeProjectDependencies>
</configuration>
<dependencies>
<dependency>
<groupId>org.eclipse.emf</groupId>
<artifactId>org.eclipse.emf.mwe2.launch</artifactId>
<version>${mwe2-version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.xtext</groupId>
<artifactId>org.eclipse.xtext.common.types</artifactId>
<version>${xtext-version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.xtext</groupId>
<artifactId>org.eclipse.xtext.generator</artifactId>
<version>${xtext-version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.xtext</groupId>
<artifactId>org.eclipse.xtext.xtext.generator</artifactId>
<version>${xtext-version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.xtext</groupId>
<artifactId>org.eclipse.xtext.xbase</artifactId>
<version>${xtext-version}</version>
</dependency>
<dependency>
<groupId>org.xtext</groupId>
<artifactId>antlr-generator</artifactId>
<version>3.2.1</version>
</dependency>
<!-- avoid warning concerning too old asm library (https://github.com/xtext-dev/maven-xtext-example/issues/25) -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.2</version>
<exclusions>
<exclusion>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
</exclusion>
<exclusion>
<groupId>asm</groupId>
<artifactId>asm-commons</artifactId>
</exclusion>
<exclusion>
<groupId>asm</groupId>
<artifactId>asm-tree</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</plugin>