Home » Java » java – How to use generated EMF model code in other Gradle subproject?-Exceptionshub

java – How to use generated EMF model code in other Gradle subproject?-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

Given the following project structure:

parent/
    settings.gradle
    app/
        src/main/java/...
        build.gradle
    model/
        src-gen/main/java/...
            Example.java
            impl/
                ExampleImpl.java
        build.gradle

In model/build.gradle I declare the required EMF packages as api dependencies, assuming they will be made available to a user of that project:

dependencies {
    api 'org.eclipse.emf:common:2.3.0-v200706262000'
    api 'org.eclipse.emf:ecore:2.3.0-v200706262000'
    api 'org.eclipse.emf:ecore-xmi:2.2.3'
}

sourceSets { main { java {
    srcDirs 'src-gen'
} } }

In app/build.gradle I declare :model as a dependency:

plugins {
    id 'java'
    id 'application'
}
dependencies {
    implementation project(':model')
    ...

However, when I run gradle run, I get the following exception (along with ~100 related ones):

> Task :model:compileJava FAILED
/.../parent/model/src-gen/main/java/org/example/parent/model/impl/ExampleImpl.java:10: error: cannot find symbol
import org.eclipse.emf.ecore.impl.MinimalEObjectImpl;
                                 ^
  symbol:   class MinimalEObjectImpl
  location: package org.eclipse.emf.ecore.impl

Why is that and what can I do about it? I want to generate an EMF based data model (:model) and use it in the other subproject (:app). I want to avoid dependencies on Eclipse.

How to&Answers: