Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » cross-project references not resolved in standalone mode
cross-project references not resolved in standalone mode [message #1709708] Wed, 30 September 2015 13:46 Go to next message
Hans-Peter Bantle is currently offline Hans-Peter BantleFriend
Messages: 5
Registered: September 2015
Junior Member
Hi,

I have splitted my model file into multiple files and put them into different projects. Once I have configured the project dependencies, this is working perfectly fine in Eclipse:
index.php/fa/23401/0/

Btw, I'm using the DSL from the Extended-15-Minutes-Tutorial: https://eclipse.org/Xtext/documentation/103_domainmodelnextsteps.html
And I have attached the actual DSL: domainmodel_dsl.zip
as well as my project files: my.project.zip

Now I'm trying to build my project with gradle (build.gradle scripts are included with the project files). But when the second project gets validated, I always end up with following error:
Starting validation for input: 'blog.dmodel'
ERROR:Couldn't resolve reference to Type 'String'. (file:/C:/dev/runtime-EclipseXtext/my.project.blog/src/main/java/blog.dmodel line : 6)
ERROR:Couldn't resolve reference to Entity 'HasAuthor'. (file:/C:/dev/runtime-EclipseXtext/my.project.blog/src/main/java/blog.dmodel line : 10)
ERROR:Couldn't resolve reference to Type 'String'. (file:/C:/dev/runtime-EclipseXtext/my.project.blog/src/main/java/blog.dmodel line : 11)
ERROR:Couldn't resolve reference to Type 'String'. (file:/C:/dev/runtime-EclipseXtext/my.project.blog/src/main/java/blog.dmodel line : 12)
ERROR:Couldn't resolve reference to Entity 'HasAuthor'. (file:/C:/dev/runtime-EclipseXtext/my.project.blog/src/main/java/blog.dmodel line : 16)
ERROR:Couldn't resolve reference to Type 'String'. (file:/C:/dev/runtime-EclipseXtext/my.project.blog/src/main/java/blog.dmodel line : 17)
:my.project.blog:xtextGenerate FAILED


Has anyone experienced a similar problem and found a solution for this? Any kind of help is very much appreciated. Thanks.
Re: cross-project references not resolved in standalone mode [message #1709713 is a reply to message #1709708] Wed, 30 September 2015 14:04 Go to previous messageGo to next message
Stefan Oehme is currently offline Stefan OehmeFriend
Messages: 159
Registered: April 2010
Location: Kiel
Senior Member

The xtextTooling configuration is only meant for dependencies of the Xtext generator itself (i.e. you add your language implementation to that).

For dependencies between projects, please use the usual compile/testCompile configurations.
Re: cross-project references not resolved in standalone mode [message #1709717 is a reply to message #1709713] Wed, 30 September 2015 14:14 Go to previous messageGo to next message
Hans-Peter Bantle is currently offline Hans-Peter BantleFriend
Messages: 5
Registered: September 2015
Junior Member
Thanks for your reply. I just modified the build.gradle file in project my.project.blog and changed the dependency configuration to:
dependencies {
   compile project(path: ':my.project.common')
}

Of course, this works fine for compile dependencies, but unfortunately not for dsl references. From my point of view, the import statement in blog.dmodel does not get resolved.
The error actually occurs in task xtextGenerate, as you can see in the above error message.
Re: cross-project references not resolved in standalone mode [message #1709741 is a reply to message #1709717] Wed, 30 September 2015 16:09 Go to previous messageGo to next message
Stefan Oehme is currently offline Stefan OehmeFriend
Messages: 159
Registered: April 2010
Location: Kiel
Senior Member

That's because your dmodel files are not in the .jar. You should put them in src/main/resources or add src/main/java to the list of resource folders.
Re: cross-project references not resolved in standalone mode [message #1709800 is a reply to message #1709741] Thu, 01 October 2015 07:49 Go to previous messageGo to next message
Hans-Peter Bantle is currently offline Hans-Peter BantleFriend
Messages: 5
Registered: September 2015
Junior Member
Adding src/main/java to the list of resource folders solved the problem. Thanks a lot.
Re: cross-project references not resolved in standalone mode [message #1709803 is a reply to message #1709800] Thu, 01 October 2015 07:51 Go to previous messageGo to next message
Stefan Oehme is currently offline Stefan OehmeFriend
Messages: 159
Registered: April 2010
Location: Kiel
Senior Member

Have a look at you jar contents, though. Adding src/main/java as a resource might lead to other source files being put in the jar, too. So you might need to add some exclude rules to it.
Re: cross-project references not resolved in standalone mode [message #1746452 is a reply to message #1709803] Sat, 29 October 2016 10:03 Go to previous messageGo to next message
Edilberto Castellanos is currently offline Edilberto CastellanosFriend
Messages: 2
Registered: October 2016
Junior Member
Hi,

xtext cross-project references not resolved in standalone mode during maven compilation. I have enhanced a bit herolanguage to model hero idols and validate the resolution of cross-project references and it runs as eclipse projects, taken into account maven dependencies, but when running as a maven install it fails to resolve them.

I upload the samples,


any help would be appreciated.

thanks.
  • Attachment: heroplus.zip
    (Size: 4.86MB, Downloaded 138 times)
  • Attachment: sample.zip
    (Size: 12.21KB, Downloaded 133 times)
Re: cross-project references not resolved in standalone mode [message #1746467 is a reply to message #1746452] Sun, 30 October 2016 08:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
<classPathLookupFilter>.</classPathLookupFilter>

is bad, that regex will match barely nothing


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: cross-project references not resolved in standalone mode [message #1746478 is a reply to message #1746467] Sun, 30 October 2016 15:01 Go to previous messageGo to next message
Edilberto Castellanos is currently offline Edilberto CastellanosFriend
Messages: 2
Registered: October 2016
Junior Member
Thank you Cristian, I had been fighting against the workflow and ResourceProviders customization, looking at wrong places.

A lot of thanks.
Re: cross-project references not resolved in standalone mode [message #1779840 is a reply to message #1746478] Sun, 14 January 2018 12:52 Go to previous messageGo to next message
Martin Trummer is currently offline Martin TrummerFriend
Messages: 17
Registered: December 2017
Junior Member
I also have a problem with simple cross-references between 2 java modules in a gradle build.

Here is my DSL-project :
Relevant parts of
X2Dsl.xtext

grammar com.tmtron.ex.xtext2.dsl.X2Dsl with org.eclipse.xtext.xbase.annotations.XbaseWithAnnotations

generate x2Dsl "http://www.example.com/ex/xtext2/dsl/X2Dsl"

x2Model:
	importSection=XImportSection?
    elements+=AbstractElement*
;

AbstractElement:
    PackageDeclaration | DomainObject | UseCase;
	
PackageDeclaration:
    'package' name=QualifiedName '{'
        elements+=AbstractElement*
    '}';		
	
DomainObject:
	'do' name=ValidID;

UseCase:
	'uc' name=ValidID 'do=' doRef=[DomainObject|ValidID];


The Inferrer-code:
X2DslJvmModelInferrer.xtend

	def dispatch void infer(DomainObject domainObject, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
 		acceptor.accept(domainObject.toClass(domainObject.fullyQualifiedName)) [
 			documentation = "generated from the domain model"
		]
	}
	
	def dispatch void infer(UseCase useCase, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
 		acceptor.accept(useCase.toClass(useCase.fullyQualifiedName)) [
 			documentation = "use-case generated from the domain model"
 			
 			val doClassRef = typeRef(useCase.doRef.fullyQualifiedName.toString)
 			members += useCase.doRef.toField(useCase.doRef.name.toFirstLower, doClassRef) => [
 				visibility = JvmVisibility.PUBLIC
 			]
		]
	}


The DSL is used in this project: dsl-usage
which uses gradle and has 2 java-modules.

Domain project
domain has a simple model, which defines a User DomainObject: model.x2dsl

package com.tmtron.test.domain {
	do User
}


the gradle build file build.gradle
makes sure that the model.x2dsl file is included in the jar:

sourceSets.main.resources.srcDirs += ["src/main/java"]


Interactors project
The interactors module
has a dependency on the domain module. Gradle build file: interactors/build.gradle
dependencies {
	implementation project(':domain')
}


and in the Interactors model interactorModel.x2dsl
, I want to reference the User domain object like this:

import com.tmtron.test.domain.User

package com.tmtron.text {
	uc GetUserName do=User
	uc SetUserName do=User
}


but the build fails (see log output)
with this error:
Error calling inferrer
ERROR:User cannot be resolved. (file:/builds/xtext2/dsl-usage/interactors/src/main/java/com/tmtron/ex/xtext2/usage/interactorModel.x2dsl line : 5 column : 20)
ERROR:User cannot be resolved. (file:/builds/xtext2/dsl-usage/interactors/src/main/java/com/tmtron/ex/xtext2/usage/interactorModel.x2dsl line : 6 column : 20)


Maybe the problem is in my inferrer?
I am not sure if this reference type is correct:
val doClassRef = typeRef(useCase.doRef.fullyQualifiedName.toString)

[Updated on: Sun, 04 September 2022 06:54]

Report message to a moderator

Re: cross-project references not resolved in standalone mode [message #1779841 is a reply to message #1779840] Sun, 14 January 2018 13:08 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
you have to list all dsl with their standalonesetups here: https://gitlab.com/xtext2/dsl-usage/blob/master/build.gradle

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: cross-project references not resolved in standalone mode [message #1779842 is a reply to message #1779841] Sun, 14 January 2018 13:14 Go to previous messageGo to next message
Martin Trummer is currently offline Martin TrummerFriend
Messages: 17
Registered: December 2017
Junior Member
Christian Dietrich wrote on Sun, 14 January 2018 13:08
you have to list all dsl with their standalonesetups here: https://gitlab.com/xtext2/dsl-usage/blob/master/build.gradle

Thanks for the fast rely. But I am not sure what you mean.
I only have one DSL and it is registered in the subprojects block: so it will be registered for both modules (domain and interactors), right?
Re: cross-project references not resolved in standalone mode [message #1779843 is a reply to message #1779842] Sun, 14 January 2018 13:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hmmm again its seems to be a bad idea to highjack the same thread for different things ....

i dont know the gradle plugin you use and the configuration "implementation"

thus i tried only this

dependencies {
implementation project(':domain')
compile project(':domain')
}

......

xtext {
version = '2.13.0'
......
}

generateXtext.classpath = configurations.compile





Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: cross-project references not resolved in standalone mode [message #1779844 is a reply to message #1779843] Sun, 14 January 2018 14:47 Go to previous message
Martin Trummer is currently offline Martin TrummerFriend
Messages: 17
Registered: December 2017
Junior Member
Christian Dietrich wrote on Sun, 14 January 2018 13:42
hmmm again its seems to be a bad idea to highjack the same thread for different things ....

Sorry, I thought this is the same issue as the original question. Thus I've asked it here.

Thanks a lot - this line helped me:
generateXtext.classpath = configurations.compile


I was not aware that we need to set the classpath - I couldn't find this in the docs of the xtext-builder gradle plugin

The Java Library Plugin is an extension to the Java plugin and allows to specify which dependencies are only needed for the implementation and which are also needed by the consumer (api dependencies will be transitively resolved).

The following works for me (in interactors/build.gradle):

dependencies {
	implementation project(':domain')
}

generateXtext.classpath = configurations.runtimeClasspath


Previous Topic:How to generate API document of DSL?
Next Topic:Code assist for DataType rules
Goto Forum:
  


Current Time: Tue Apr 16 22:32:47 GMT 2024

Powered by FUDForum. Page generated in 1.89088 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top