Xtext and Maven

DSL’s are the new buzzword together with Cloud, not only since Groovy or similiar tools. With Xtext you get a really easy to use tool for creating an Eclipse-based editor and code generator. Xtext is a powerfull toolset, which eases the creation of your own DSL. To find out more about Xtext please check my presentation or take a look at the example for building Xtext projects with Maven and Tycho on GitHub.

General Setup

  1. Create new Xtext project see Github-Commit
  2. Create  Folder structure to get relative links working. Therefore the references to the test-projects needs to be adopted to get the build done.
  3. Initial build is done in Eclipse to get the first time generated classes created.
  4. Create projects maven-parent, repository and target. Also change the compile target for Eclipse to target/classes.
  5. Now a first build can be done
  6. Therefore make the target platform module available in the lokal m2 repository via mvn install: Change to the targetplattform project (org.xtext.example.targetplatform) and run mvn install:

    org.xtext.example.targetplatform mare$ mvn install

  7. The something like this should show up:

    [INFO] BUILD SUCCESS

  8. Now change to  the repository project (releng/org.xtext.example.repository) and run  mvn install to get the repository installed.
    This should be lead to the following message:

    [INFO] Computing target platform for MavenProject: org.xtext.example:org.xtext.example.repository:0.5.0-SNAPSHOT @ /Users/mare/Documents/Programmierung/git/github/xText/Xtext-Maven-BuildExample/releng/org.xtext.example.repository/pom.xml

  9. After that several downloads will start. This can take up to 10 minutes.
  10. Now the desired plugin can be built with maven. Change therefore to the parent project (releng/org.xtext.example.parent) and enter the following command:
    mbpromare:org.xtext.example.parent mare$ mvn install
  11. Now the Xtext build with Tacho is working:
  12. mbpromare:org.xtext.example.maven.mydsl1 mare$ mvn compile
    [INFO] Scanning for projects... 
    [INFO] Computing target platform for MavenProject: org.xtext.example.maven:org.xtext.example.maven.mydsl1:0.5.0-SNAPSHOT @ /Users/mare/Documents/Programmierung/git/github/xText/Xtext-MavenExample/plugins/org.xtext.example.maven.mydsl1/pom.xml 
    [INFO] Resolving dependencies of MavenProject: org.xtext.example.maven:org.xtext.example.maven.mydsl1:0.5.0-SNAPSHOT @ /Users/mare/Documents/Programmierung/git/github/xText/Xtext-MavenExample/plugins/org.xtext.example.maven.mydsl1/pom.xml 
    [INFO] Resolving class path of MavenProject: org.xtext.example.maven:org.xtext.example.maven.mydsl1:0.5.0-SNAPSHOT @ /Users/mare/Documents/Programmierung/git/github/xText/Xtext-MavenExample/plugins/org.xtext.example.maven.mydsl1/pom.xml 
    [INFO] 
    [INFO] ------------------------------------------------------------------------ 
    [INFO] Building org.xtext.example.maven.mydsl1 0.5.0-SNAPSHOT 
    [INFO] ------------------------------------------------------------------------ 
    [INFO] 
    [INFO] --- tycho-packaging-plugin:0.15.0:build-qualifier (default-build-qualifier) @ org.xtext.example.maven.mydsl1 ---
    [INFO] 
    [INFO] --- tycho-packaging-plugin:0.15.0:validate-id (default-validate-id) @ org.xtext.example.maven.mydsl1 --- 
    [INFO] 
    [INFO] --- tycho-packaging-plugin:0.15.0:validate-version (default-validate-version) @ org.xtext.example.maven.mydsl1 --- 
    [INFO] 
    [INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ org.xtext.example.maven.mydsl1 --- 
    [debug] execute contextualize 
    [INFO] Using 'ISO-8859-1' encoding to copy filtered resources. 
    [INFO] skip non existing resourceDirectory /Users/mare/Documents/Programmierung/git/github/xText/Xtext-MavenExample/plugins/org.xtext.example.maven.mydsl1/src/main/resources 
    [INFO] 
    [INFO] --- tycho-compiler-plugin:0.15.0:compile (default-compile) @ org.xtext.example.maven.mydsl1 ---
    [INFO] Nothing to compile - all classes are up to date 
    [WARNING] Source directory /Users/mare/Documents/Programmierung/git/github/xText/Xtext-MavenExample/plugins/org.xtext.example.maven.mydsl1/src-gen does not exist 
    [WARNING] Source directory /Users/mare/Documents/Programmierung/git/github/xText/Xtext-MavenExample/plugins/org.xtext.example.maven.mydsl1/xtend-gen does not exist 
    [INFO] ------------------------------------------------------------------------ 
    [INFO] BUILD SUCCESS 
    [INFO] ------------------------------------------------------------------------ 
    [INFO] Total time: 48.161s 
    [INFO] Finished at: Tue Oct 02 17:01:34 CEST 2012 
    [INFO] Final Memory: 51M/104M 
    [INFO] ------------------------------------------------------------------------
  13. For completion the update site, product configuration and feature project should be created. Optional a SDK project can be created. Change to releng/org.xtext.example.parent and run mvn install.The result should look like this:
    [INFO] --- maven-install-plugin:2.3.1:install (default-install) @ org.xtext.example.product ---
    [INFO] Installing /Users/mare/Documents/Programmierung/git/github/xText/Xtext-Maven-BuildExample/releng/org.xtext.example.product/target/org.xtext.example.product-0.5.0-SNAPSHOT.zip to /Users/mare/.m2/repository/org/xtext/example/org.xtext.example.product/0.5.0-SNAPSHOT/org.xtext.example.product-0.5.0-SNAPSHOT.zip
    [INFO] Installing /Users/mare/Documents/Programmierung/git/github/xText/Xtext-Maven-BuildExample/releng/org.xtext.example.product/pom.xml to /Users/mare/.m2/repository/org/xtext/example/org.xtext.example.product/0.5.0-SNAPSHOT/org.xtext.example.product-0.5.0-SNAPSHOT.pom
    [INFO] Installing /Users/mare/Documents/Programmierung/git/github/xText/Xtext-Maven-BuildExample/releng/org.xtext.example.product/target/products/org.xtext.example.product-win32.win32.x86.zip to /Users/mare/.m2/repository/org/xtext/example/org.xtext.example.product/0.5.0-SNAPSHOT/org.xtext.example.product-0.5.0-SNAPSHOT-win32.win32.x86.zip
    [INFO] Installing /Users/mare/Documents/Programmierung/git/github/xText/Xtext-Maven-BuildExample/releng/org.xtext.example.product/target/products/org.xtext.example.product-win32.win32.x86_64.zip to /Users/mare/.m2/repository/org/xtext/example/org.xtext.example.product/0.5.0-SNAPSHOT/org.xtext.example.product-0.5.0-SNAPSHOT-win32.win32.x86_64.zip
    [INFO] Installing /Users/mare/Documents/Programmierung/git/github/xText/Xtext-Maven-BuildExample/releng/org.xtext.example.product/target/products/org.xtext.example.product-macosx.cocoa.x86_64.zip to /Users/mare/.m2/repository/org/xtext/example/org.xtext.example.product/0.5.0-SNAPSHOT/org.xtext.example.product-0.5.0-SNAPSHOT-macosx.cocoa.x86_64.zip
    [INFO] Installing /Users/mare/Documents/Programmierung/git/github/xText/Xtext-Maven-BuildExample/releng/org.xtext.example.product/target/products/org.xtext.example.product-macosx.cocoa.x86.zip to /Users/mare/.m2/repository/org/xtext/example/org.xtext.example.product/0.5.0-SNAPSHOT/org.xtext.example.product-0.5.0-SNAPSHOT-macosx.cocoa.x86.zip
    [INFO] Installing /Users/mare/Documents/Programmierung/git/github/xText/Xtext-Maven-BuildExample/releng/org.xtext.example.product/target/products/org.xtext.example.product-linux.gtk.x86.zip to /Users/mare/.m2/repository/org/xtext/example/org.xtext.example.product/0.5.0-SNAPSHOT/org.xtext.example.product-0.5.0-SNAPSHOT-linux.gtk.x86.zip
    [INFO] Installing /Users/mare/Documents/Programmierung/git/github/xText/Xtext-Maven-BuildExample/releng/org.xtext.example.product/target/products/org.xtext.example.product-linux.gtk.x86_64.zip to /Users/mare/.m2/repository/org/xtext/example/org.xtext.example.product/0.5.0-SNAPSHOT/org.xtext.example.product-0.5.0-SNAPSHOT-linux.gtk.x86_64.zip
    [INFO] ------------------------------------------------------------------------
    [INFO] Reactor Summary:
    [INFO] 
    [INFO] org.xtext.example.targetplatform .................. SUCCESS [0.677s]
    [INFO] org.xtext.example.parent .......................... SUCCESS [0.155s]
    [INFO] org.xtext.example.maven.mydsl1 .................... SUCCESS [30.381s]
    [INFO] org.xtext.example.maven.mydsl1.ui ................. SUCCESS [1.910s]
    [INFO] org.xtext.example.maven.mydsl1.tests .............. SUCCESS [3.774s]
    [INFO] org.xtext.example.maven.mydsl2 .................... SUCCESS [18.021s]
    [INFO] org.xtext.example.maven.mydsl2.ui ................. SUCCESS [1.636s]
    [INFO] org.xtext.example.maven.mydsl2.tests .............. SUCCESS [2.695s]
    [INFO] org.xtext.example.feature ......................... SUCCESS [0.310s]
    [INFO] org.xtext.example.updatesite ...................... SUCCESS [5.264s]
    [INFO] org.xtext.example.product ......................... SUCCESS [1:17.585s]
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 2:43.112s
    [INFO] Finished at: Fri Oct 19 13:35:45 CEST 2012
    [INFO] Final Memory: 42M/104M
    [INFO] ------------------------------------------------------------------------

You find more about Tycho here:

CI-Integration

Here is a sample Jenkins configuration. Really import is the private maven repository:

Xtext maven jenkins.png

Example in CloudBees

Errors

Versions-Fehler
mbpromare:org.xtext.example.maven.mydsl1 mare$ mvn compile [INFO] Scanning for projects... 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 18.336s
[INFO] Finished at: Thu Oct 18 16:43:23 CEST 2012
[INFO] Final Memory: 16M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.eclipse.tycho:tycho-packaging-plugin:0.15.0:validate-version (default-validate-version) on project org.xtext.example.maven.mydsl1: Unqualified OSGi version 1.0.0.qualifier must match unqualified Maven version 0.5.0-SNAPSHOT for SNAPSHOT builds -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :org.xtext.example.maven.mydsl1

The above error comes up if the version number within Maven and Eclipse differ.  0.5.0.qualifier in manifest means 0.5.0.SNAPSHOT to Maven. They need to be adopted, either in the pom.xml or MANIFEST.MF

This entry was posted in IT and tagged , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.