Adding an external Dependency to my maven-tycho build [message #1785774] |
Thu, 19 April 2018 14:40 |
Lukas Schaus Messages: 37 Registered: October 2016 |
Member |
|
|
Hello,
I am having trouble to add a dependency to an external java library via maven in my maven-tycho build.
This is my Environment:
- Windows 7 x64
- Xtext 2.12
- Eclipse oxygen
I created the example project using the project wizard. I checked the eclipseplugin, support for testing, selected the maven build system and used the plain source layout.
Then i ran mvn install on the /org.xtext.example.mydsl project. The build was successfull.
Then i used a json library in the generator :
/*
* generated by Xtext 2.12.0.M1
*/
package org.xtext.example.mydsl.generator
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.generator.AbstractGenerator
import org.eclipse.xtext.generator.IFileSystemAccess2
import org.eclipse.xtext.generator.IGeneratorContext
import org.json.JSONObject
/**
* Generates code from your model files on save.
*
* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation
*/
class MyDslGenerator extends AbstractGenerator {
override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
val myString = new JSONObject()
.put("JSON", "Hello, World!").toString();
}
}
If I run the same mvn install now i get an error as expected. The error is raised during the xtend compilation
[INFO] --- xtend-maven-plugin:2.12.0.M1:compile (default) @ org.xtext.example.mydsl ---
[ERROR]
ERROR: MyDslGenerator.xtend - D:\Arbeits_Artefakte\2018\09\mvnWs\org.xtext.example.mydsl.parent\org.xtext.example.mydsl\src\org\xtext\example\mydsl\generator\MyDslGenerator.xtend
10: org.json.JSONObject cannot be resolved to a type.
[ERROR]
ERROR: MyDslGenerator.xtend - D:\Arbeits_Artefakte\2018\09\mvnWs\org.xtext.example.mydsl.parent\org.xtext.example.mydsl\src\org\xtext\example\mydsl\generator\MyDslGenerator.xtend
20: JSONObject cannot be resolved.
Then i added the dependency into the /org.xtext.example.mydsl/pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.xtext.example.mydsl</groupId>
<artifactId>org.xtext.example.mydsl.parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>org.xtext.example.mydsl</artifactId>
<packaging>eclipse-plugin</packaging>
<dependencies>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180130</version>
</dependency>
</dependencies>
<build>
<plugins>
...
Now the build fails in a later phase, where the java sources are compiled:
ERROR] Failed to execute goal org.eclipse.tycho:tycho-compiler-plugin:1.0.0:compile (default-compile) on project org.xtext.example.mydsl: Compilation failure: Compilation failure:
[ERROR] D:\Arbeits_Artefakte\2018\09\mvnWs\org.xtext.example.mydsl.parent\org.xtext.example.mydsl\xtend-gen\org\xtext\example\mydsl\generator\MyDslGenerator.java:[10]
[ERROR] import org.json.JSONObject;
[ERROR] ^^^^^^^^
[ERROR] The import org.json cannot be resolved
[ERROR] D:\Arbeits_Artefakte\2018\09\mvnWs\org.xtext.example.mydsl.parent\org.xtext.example.mydsl\xtend-gen\org\xtext\example\mydsl\generator\MyDslGenerator.java:[21]
[ERROR] final String myString = new JSONObject().put("JSON", "Hello, World!").toString();
[ERROR] ^^^^^^^^^^
[ERROR] JSONObject cannot be resolved to a type
[ERROR] 2 problems (2 errors)
If somebody knows where in the pom and how the dependency should be added I would be very thannkfull if he or she could drop me a hint. Or do I have to make some adjustments to the manifest.mf?
It seems to ba a fairly standard question but unfortunately I did not find any answers on google.
Tahanks in advance,
Lukas
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03656 seconds