Gradle error when deploying service builder in liferay

Viewed 17

I am experiencing an error when trying to run my custom service builder on my localhost. Gradle gives this error:

MESSAGE Problem with deploying bundle: gogo: BundleException: Could not resolve module: com.liferay.trotspots.web [1569]
  Unresolved requirement: Import-Package: com.liferay.asset.constants; version="[1.1.0,2.0.0)"

weirdly however in the module com.liferay.trotspot.web I am not importing com.liferat.asset.constants. This is my build gradle file for the module:

apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'eclipse'

sourceCompatibility = 1.8
targetCompatibility = 1.8

//Need for Windows
def defaultEncoding = 'UTF-8'

dependencies {
    compile group: "biz.aQute.bnd", name: "biz.aQute.bndlib", version: "3.5.0"
    compile group: "org.apache.poi", name: "poi"
    compile group: "org.apache.poi", name: "poi-ooxml"
    compile group: "org.apache.poi", name: "poi-ooxml-schemas"

    compileOnly group: "com.liferay.portal", name: "release.portal.api"

    compileOnly group: "com.liferay", name: "com.liferay.application.list.api"
    compileOnly group: "com.liferay", name: "com.liferay.asset.api"
    compileOnly group: "com.liferay", name: "com.liferay.asset.display.page.api"
    compileOnly group: "com.liferay", name: "com.liferay.asset.display.page.item.selector.api"
    compileOnly group: "com.liferay", name: "com.liferay.asset.info.display.api"
    compileOnly group: "com.liferay", name: "com.liferay.asset.taglib"
    compileOnly group: "com.liferay", name: "com.liferay.comment.taglib"
    compileOnly group: "com.liferay", name: "com.liferay.frontend.taglib"
    compileOnly group: "com.liferay", name: "com.liferay.frontend.taglib.clay"
    compileOnly group: "com.liferay", name: "com.liferay.frontend.taglib.soy"
    compileOnly group: "com.liferay", name: "com.liferay.frontend.taglib.util"
    compileOnly group: "com.liferay", name: "com.liferay.info.api"
    compileOnly group: "com.liferay", name: "com.liferay.item.selector.api"
    compileOnly group: "com.liferay", name: "com.liferay.item.selector.criteria.api"
    compileOnly group: "com.liferay", name: "com.liferay.item.selector.taglib"
    compileOnly group: "com.liferay", name: "com.liferay.petra.reflect"
    compileOnly group: "com.liferay", name: "com.liferay.petra.string"
    compileOnly group: "com.liferay", name: "com.liferay.petra.function"
    compileOnly group: "com.liferay", name: "com.liferay.trash.api"
    compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel"
    compileOnly group: "com.liferay.portal", name: "com.liferay.util.taglib"
    compileOnly group: "javax.portlet", name: "portlet-api"
    compileOnly group: "javax.servlet.jsp", name: "jsp-api"
    compileOnly group: "jstl", name: "jstl"
    compileOnly group: "org.apache.felix", name: "org.apache.felix.http.servlet-api", version: "1.1.+"
    compileOnly group: "org.osgi", name: "org.osgi.service.component.annotations", version: "1.3.0"
    compileOnly group: 'org.slf4j', name: 'slf4j-api', version: '1.7.+'
    compileOnly project(":modules:trots:trots-api")
    compileOnly project(":modules:trots:trots-service")
}

I get the same error for the api and service module but with different packages. I figured if I knew how to resolve this error I would do the same for the other two. I've tried to add a specific version to the "com.liferat.asset.api" package but this changes nothing. Does anybody know what what else I can do to fix this error?

1 Answers

With the inclusion of

compileOnly group: "com.liferay.portal", name: "release.portal.api"

you should be able to omit any and all of the Liferay-related dependencies from your buildfile (at the very least all of the com.liferay grouped ones, but likely all of the ones that don't have a version signature)

That being said, if you're missing a transitive dependency, that might be because your workspace targets an older version than you're actually running. Since the rolling updates on 7.4, you should compile for your target version.

Make sure that your workspace's settings (gradle.properties) contain the proper version that you want to compile for - e.g.:

liferay.workspace.product=portal-7.4-ga41

If you still compile for GA1, but deploy on GA41, you'll likely run into these kinds of problems. Often you can can differ by a few versions, but occasionally (when you just hit the version where a package was bumped up one version), you'll need to hit the right release.

And an unrelated code-review issue: You should make sure that any service-builder related code only depends on your -api module, and not on the -service implementation. If necessary, add commonly used code/interfaces to your API, or to a third bundle to keep your dependencies clean.

Related