Search code examples
liferay

I can't build Liferay Spring MVC Portlet Project


I can't build my Liferay Spring MVC Portlet Project.

Here is error in Markers Here is error in Console

Full error report in console:

FAILURE: Build failed with an exception.

What went wrong:
A problem occurred configuring root project 'HelloWorld'.
Dependencies can not be declared against the `compileClasspath` configuration.

Try:
Run with --stacktrace option to get the stack trace.
Run with --info or --debug option to get more log output.
Run with --scan to get full insights.

Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/8.0.2/userguide/command_line_interface.html#sec:command_line_warnings

CONFIGURE FAILED in 939ms

I have OpenJDK 11 installed on my Windows 11

Here is build.gredle content:

plugins {
     id "com.liferay.plugin" version "3.18.0"
     id "java"
}

repositories {
    mavenLocal()
    mavenCentral()
    maven {
        url "https://repository-cdn.liferay.com/nexus/content/groups/public"
    }
}

dependencies {
    implementation "javax.portlet:portlet-api:2.0"
    implementation "javax.servlet:javax.servlet-api:3.0.1"
    implementation "com.liferay.portal:com.liferay.portal.kernel:7.4.3.70-ga70"
    implementation "org.springframework:spring-webmvc-portlet:5.3.15.RELEASE"
    }

    sourceCompatibility = "1.8"
    targetCompatibility = "1.8"

    liferay {
        portalVersion = "7.4.3.70-ga70"
    }

    tasks.withType(JavaCompile) {
        options.encoding = 'UTF-8'
    }

    task wrapper(type: Wrapper) {
        gradleVersion = '8.0.2'
    }

Here is gredle.properties

liferay.workspace.bundle.dist.include.metadata = true
liferay.workspace.modules.dir = modules
liferay.workspace.themes.dir = themes
liferay.workspace.wars.dir = modules
microsoft.translator.subscription.key = 
liferay.workspace.product = dxp-7.4-u71
target.platform.index.sources = false
org.gradle.jvmargs=-Dfile.encoding=UTF-8

Here is gredle/gredle-wrapper.properties content:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

What I do wrong? I have also HelloWorld.java and helloworld.jsp files in folders ./src/main/com/example/helloworld/portlet and ./src/main/resources


Solution

  • I'm typically building within a Liferay Workspace, where many of the details are handled by the environment (think of it as an "opinionated gradle"). So take this with a grain of salt:

    What looks suspicious for me are these items:

    implementation "com.liferay.portal:com.liferay.portal.kernel:7.4.3.70-ga70"
    

    When I see dependencies on com.liferay.portal.kernel, I expect version numbers that are the semantic version of that module, and annoyingly, these semantic versions have nothing to do with the whole product's release (that's where Liferay Workspace helps tremendously). In fact, looking at the current code, that bundle seems to be version 106.0.0 at the time of me writing this answer.

    You also have a mismatch of declaring a dependency on portalVersion = "7.4.3.70-ga70" (aka "Liferay Portal CE, GA70") and liferay.workspace.product = dxp-7.4-u71 (aka "Liferay DXP, U71") (though, as you don't use workspace, this might only be confusing, but not add to the problems)

    You might want to compare your current setup to the available blade-sample for a spring-mvc portlet, though you'll certainly need to adapt the version numbers in those dependencies to your version's actual dependencies.

    Unfortunately, the spring-mvc portlet sample seems only to be available in pure gradle, not in liferay-workspace (it should be everywhere), if you compare the Liferay-dependencies of the spring-mvc sample with the jsp-portlet sample: They're so much easier in Liferay Workspace:

    spring-mvc dependency excerpt, pure gradle:

    compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "5.4.0"
    compileOnly group: "javax.portlet", name: "portlet-api", version: "2.0"
    compileOnly group: "javax.servlet", name: "javax.servlet-api", version: "3.1.0"
    compileOnly group: "javax.validation", name: "validation-api", version: "2.0.1.Final"
    compileOnly group: "org.osgi", name: "org.osgi.service.component.annotations", version: "1.3.0"
    compileOnly group: "org.slf4j", name: "slf4j-api", version: "1.7.25"
    cssBuilder group: "com.liferay", name: "com.liferay.css.builder", version: "3.0.2"
    
    portalCommonCSS group: "com.liferay", name: "com.liferay.frontend.css.common", version: "5.0.2"
    

    jsp-portlet full dependencies, using Liferay Workspace:

    dependencies {
        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: "org.osgi", name: "org.osgi.service.component.annotations"
    }
    

    The versions for these modules are automagically determined through the workspace's "target platform", e.g. the value of liferay.workspace.product in the workspace's gradle.properties.

    In fact, you can further simplify the dependencies to one of these lines (depending on targeting CE or DXP):

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

    While this does not necessarily point to the single root cause, it might give you enough food for thought to find the issue yourself (or try Liferay Workspace handling dependencies for you - it also makes future upgrades a lot easier)