Could not find method compileOnly() for arguments

54 Views Asked by At

I'm building an portlet service for Liferay using intellij Idea, but I am strugling in importing a module made by gradle as dependency management

the exption is

Build file 'G:\Projets\[...]\build.gradle' line: 2

A problem occurred evaluating project ':xxx-service-api'.
> Could not find method compileOnly() for arguments [{group=com.liferay, name=com.liferay.petra.lang, version=5.2.1}] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

the build.gradle

dependencies {
    compileOnly   group: "com.liferay", name: "com.liferay.petra.lang", version: "5.2.1"
    compileOnly   group: "com.liferay", name: "com.liferay.petra.string", version: "5.3.4"
    compileOnly   group: "com.liferay", name: "com.liferay.portal.aop.api", version: "3.0.5"
    compileOnly   group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "13.0.0"
    compileOnly   group: "org.osgi", name: "org.osgi.annotation.versioning", version: "1.1.2"
    compileOnly   group: "org.osgi", name: "org.osgi.core", version: "6.0.0"
    compileOnly   group: "org.osgi", name: "org.osgi.service.component.annotations", version: "1.5.1"
    compileOnly   group: "com.liferay", name: "com.liferay.osgi.util", version: "8.1.0"
    compileOnly   group: "javax.portlet", name: "portlet-api", version: "3.0.1"
    compileOnly   group: "org.slf4j", name: "slf4j-api", version: "1.7.2"
}

Im using gradle 5.6.4 and liferay dxp-7.4

2

There are 2 best solutions below

2
Simon Jacobs On

Make sure you apply the Java plugin if you want to use compileOnly.

plugins {
    id('java')
}
0
Kristof Mols On

If it is a new project, I propose you create a Liferay workspace using the Blace CLI blade init -v [Liferay version] [workspace name] and also use the CLI for creating your modules blade create.

The dependency management will be handled by the default configuration in the CLI and will look a bit like this:

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

You might get around your issue by using this package manually as it contains all the code currently in your dependencies (and more)

Even if it is an existing project, you can create a new workspace and copy the configuration it generates.

Another issue can be that your repositories are not defined correctly, so your dependencies cannot be found anyway.

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

        maven {
            url "https://repository.liferay.com/nexus/content/groups/public"
        }
    }

Sources: