Skip to content

Commit

Permalink
Add separate page on building Spoofax languages with Maven.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gohla committed Apr 30, 2020
1 parent cf436b3 commit 745bc29
Show file tree
Hide file tree
Showing 3 changed files with 178 additions and 142 deletions.
144 changes: 2 additions & 142 deletions source/langdev/build/ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,147 +15,7 @@ The second step is configuring Jenkins to perform these maven builds and publish

## Local Maven Build

The local Maven build starts from the generate new project wizard (you need the generated files).
`New Project` > `New Spoofax language project` > select all generation options. This generates 6 projects in total.

(Move the six projects to a new folder.)
Create a parent pom.xml in this folder:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<modelVersion>4.0.0</modelVersion>
<artifactId>Entity.build</artifactId>
<version>0.1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<parent>
<groupId>org.metaborg</groupId>
<artifactId>parent</artifactId>
<version>|rel-version|</version>
<relativePath />
</parent>

<modules>
<module>Entity</module>
<module>Entity.eclipse</module>
<module>Entity.eclipse.feature</module>
<module>Entity.eclipse.site</module>
<module>Entity.test</module>
</modules>

<repositories>
<repository>
<id>metaborg-release-repo</id>
<url>http://artifacts.metaborg.org/content/repositories/releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>metaborg-snapshot-repo</id>
<url>http://artifacts.metaborg.org/content/repositories/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spoofax-eclipse-repo</id>
<url>http://artifacts.metaborg.org/content/unzip/releases-unzipped/org/metaborg/org.metaborg.spoofax.eclipse.updatesite/|rel-version|/org.metaborg.spoofax.eclipse.updatesite-|rel-version|-assembly.zip-unzip/</url>
<layout>p2</layout>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>metaborg-release-repo</id>
<url>http://artifacts.metaborg.org/content/repositories/releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>metaborg-snapshot-repo</id>
<url>http://artifacts.metaborg.org/content/repositories/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

</project>
```

Copy the `.mvn` folder from your language folder to the parent folder. e.g. `Entity/Entity/.mvn -> Entity/.mvn`.
(Error message otherwise: `[ERROR] Failed to execute goal org.metaborg:spoofax-maven-plugin:2.1.0-SNAPSHOT:clean (default-clean) on project Entity: Building clean input failed unexpectedly: Language for dependency org.metaborg:org.metaborg.meta.lang.esv:2.1.0-SNAPSHOT does not exist -> [Help 1]`)

Fix the generated test yaml file (known issue) e.g. `Entity/Entity.test/metaborg.yaml`.
(Error message otherwise: `[ERROR] Field 'id' must be set`)

```yaml
---
dependencies:
compile:
- org.example:Entity:0.1.0-SNAPSHOT
- org.metaborg:org.metaborg.meta.lang.spt:${metaborgVersion}
```
to
```yaml
---
id: org.example:Entity.test:0.1.0-SNAPSHOT
name: Entity
dependencies:
compile:
- org.example:Entity:0.1.0-SNAPSHOT
- org.metaborg:org.metaborg.meta.lang.spt:${metaborgVersion}
```

The maven build should now succeed:

```
[INFO] ------------------------------------------------------------------------
[INFO] Building Entity.build 0.1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ Entity.build ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Entity ............................................. SUCCESS [ 31.033 s]
[INFO] Entity.eclipse ..................................... SUCCESS [ 1.252 s]
[INFO] Entity.eclipse.feature ............................. SUCCESS [ 0.469 s]
[INFO] Entity.eclipse.site ................................ SUCCESS [ 3.776 s]
[INFO] Entity.test ........................................ SUCCESS [ 0.140 s]
[INFO] Entity.build ....................................... SUCCESS [ 0.013 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 51.354 s
[INFO] Finished at: 2016-09-16T16:58:25+02:00
[INFO] Final Memory: 280M/963M
[INFO] ------------------------------------------------------------------------
```
Follow the [guide for getting a local Maven build](maven.md) going first.

## Build on Jenkins
(Note: can be skipped in GitHub organizations MetaBorg and MetaBorgCube)
Expand Down Expand Up @@ -286,4 +146,4 @@ Similar to Jenkins, you can add a build status badge by adding the following to

```
![Build status](https://github.com/namespace/project/workflows/CI/badge.svg)
```
```
1 change: 1 addition & 0 deletions source/langdev/build/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ This is the reference manual on build and development tools for Spoofax language
:maxdepth: 2
:numbered:

maven
ci
env/intellij/index
175 changes: 175 additions & 0 deletions source/langdev/build/maven.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# Maven Builds

This page describes how to build Spoofax languages with Maven.

## Requirements

### JDK8 or higher

A recent version of JDK 8 or higher is required to build Spoofax languages with Maven.
Old versions may not accept the LetsEncrypt certificate of our artifact server.
We try to keep Spoofax compatible with newer JDKs (such as JDK13) as well, but if they do not work, please try JDK8.

### Maven

We require Maven version 3.5.4 or higher, except Maven version 3.6.1 or 3.6.2 (due to bugs in those Maven versions).
Maven can be downloaded and installed from https://maven.apache.org/download.cgi.
On macOs, Maven can be easily installed with Homebrew by executing ``brew install maven``.

Confirm the installation and version by running ``mvn --version``.

By default, Maven does not assign a lot of memory to the JVM that it runs in, which may lead to out of memory exceptions during builds.
To increase the allocated memory, set the `MAVEN_OPTS` environment variable:

```shell
export MAVEN_OPTS="-Xms512m -Xmx1024m -Xss16m"
```

To make this permanent, add this line to your `.bashrc`/`.profile` or equivalent for your operating system/shell.

## Maven Build

The local Maven build starts from the generate new project wizard (you need the generated files).
`New Project` > `New Spoofax language project` > select all generation options.
This generates 6 projects in total.
In this tutorial, our language name and ID is `entity`.

Move the six projects to a new parent directory, and create a `pom.xml` file in this directory with the following contents:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<modelVersion>4.0.0</modelVersion>
<artifactId>entity.build</artifactId>
<version>0.1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<parent>
<groupId>org.metaborg</groupId>
<artifactId>parent</artifactId>
<version>REPLACEME_SPOOFAX_VERSION</version>
<relativePath />
</parent>

<modules>
<module>entity</module>
<module>entity.eclipse</module>
<module>entity.eclipse.feature</module>
<module>entity.eclipse.site</module>
<module>entity.test</module>
</modules>

<repositories>
<repository>
<id>metaborg-release-repo</id>
<url>https://artifacts.metaborg.org/content/repositories/releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>metaborg-snapshot-repo</id>
<url>https://artifacts.metaborg.org/content/repositories/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spoofax-eclipse-repo</id>
<url>https://artifacts.metaborg.org/content/unzip/releases-unzipped/org/metaborg/org.metaborg.spoofax.eclipse.updatesite/|rel-version|/org.metaborg.spoofax.eclipse.updatesite-|rel-version|-assembly.zip-unzip/</url>
<layout>p2</layout>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>metaborg-release-repo</id>
<url>https://artifacts.metaborg.org/content/repositories/releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>metaborg-snapshot-repo</id>
<url>https://artifacts.metaborg.org/content/repositories/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

</project>
```

and replace `REPLACEME_SPOOFAX_VERSION` with the version of Spoofax you are using.

Copy the `.mvn` folder from your language folder to the parent folder. e.g. `root/entity/.mvn -> root/.mvn`.
(Error message otherwise: `[ERROR] Failed to execute goal org.metaborg:spoofax-maven-plugin:2.1.0-SNAPSHOT:clean (default-clean) on project entity: Building clean input failed unexpectedly: Language for dependency org.metaborg:org.metaborg.meta.lang.esv:2.1.0-SNAPSHOT does not exist -> [Help 1]`)

Fix the generated test yaml file (known issue) e.g. `root/entity.test/metaborg.yaml`.
(Error message otherwise: `[ERROR] Field 'id' must be set`)

```yaml
---
dependencies:
compile:
- org.example:entity:0.1.0-SNAPSHOT
- org.metaborg:org.metaborg.meta.lang.spt:${metaborgVersion}
```
to
```yaml
---
id: org.example:entity.test:0.1.0-SNAPSHOT
name: entity
dependencies:
compile:
- org.example:entity:0.1.0-SNAPSHOT
- org.metaborg:org.metaborg.meta.lang.spt:${metaborgVersion}
```

Now you can build the language with `mvn clean verify`, with the final output succeeding with something like:

```
[INFO] ------------------------------------------------------------------------
[INFO] Building entity.build 0.1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ entity.build ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] entity ............................................. SUCCESS [ 31.033 s]
[INFO] entity.eclipse ..................................... SUCCESS [ 1.252 s]
[INFO] entity.eclipse.feature ............................. SUCCESS [ 0.469 s]
[INFO] entity.eclipse.site ................................ SUCCESS [ 3.776 s]
[INFO] entity.test ........................................ SUCCESS [ 0.140 s]
[INFO] entity.build ....................................... SUCCESS [ 0.013 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 51.354 s
[INFO] Finished at: 2016-09-16T16:58:25+02:00
[INFO] Final Memory: 280M/963M
[INFO] ------------------------------------------------------------------------
```

0 comments on commit 745bc29

Please sign in to comment.