Liferay 7.2 No value has been specified for property 'apiDir' - gradle

I created a module project using servicebuild template (gradebook-api, gradebook-service), but i have an error after an export package com.liferay.training.gradebook.validator in api below
Bundle-Name: gradebook-api
Bundle-SymbolicName: com.liferay.training.gradebook.api
Bundle-Version: 1.0.0
Export-Package: \
com.liferay.training.gradebook.exception,\
com.liferay.training.gradebook.model,\
com.liferay.training.gradebook.service,\
com.liferay.training.gradebook.service.persistence,\
com.liferay.training.gradebook.validator
-check: EXPORTS
-includeresource: META-INF/service.xml=../gradebook-service/service.xml
i have a problem in the BuildService gradle task that's says :
Some problems were found with the configuration of task
':modules:gradebook:gradebook-api:buildService' (type
'BuildServiceTask').
File 'C:\Liferay\ide-workspace\training-workspace\modules\gradebook\gradebook-api\service.xml'
specified for property 'inputFile' does not exist.
No value has been specified for property 'apiDir'.
And this is a how I add the api module as dependency in service.
dependencies {
compileOnly group: "com.liferay", name: "com.liferay.petra.io"
compileOnly group: "com.liferay", name: "com.liferay.petra.lang"
compileOnly group: "com.liferay", name: "com.liferay.petra.string"
compileOnly group: "com.liferay", name: "com.liferay.portal.aop.api"
compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel"
compileOnly group: "org.osgi", name: "org.osgi.annotation.versioning"
compileOnly group: "org.osgi", name: "org.osgi.core"
compileOnly group: "org.osgi", name: "org.osgi.service.component.annotations"
compileOnly group: "javax.portlet", name: "portlet-api"
compileOnly group: "javax.servlet", name: "javax.servlet-api"
compile project(":modules:gradebook:gradebook-api")
}
buildService {
apiDir = "../gradebook-api/src/main/java"
}
group = "com.liferay.training.gradebook"
I am trying to create new Liferay workspace but i got the same error (May be this is an error with Gradle)

Be sure, you run gradle task in the corresponding folder (in gradebook-service folder). I got similar error when I ran it in upper folder which contains api and service folder.

Until recently I have only worked on LR 7.0, but the last day or so have been playing with 7.3. I encountered the exact issue you describe.
The only solution I found was to copy service.xml from gradebook-service into the root of both my gradebook-api and gradebook-web modules and also add the following to the build.gradle files of both the gradebook-api and gradebook-web modules:
buildService {
apiDir = "../gradebook-api/src/main/java"
}
After that service builder ran successfully. There may be a cleaner way around it, but this worked for me.

service.xml should stay in service module only. Here, it look you need few checks.
api module dependency should be compileonly. not in compile
scope.
block order also matters in gradle file. move below block
at the top of the file.
buildService {
apiDir = "../gradebook-api/src/main/java"
}
not sure why you need -check:exports header in bnd file. As, that is not required normally.

In the Gradle task tab, go to your specific module service folder and then build it from there. Don't forget to refresh your gradle by pressing Cntrl+F5.
This Worked for me.

I had the same situation and just added the buildService{...} in build.gradle in the api module.
buildService {
apiDir = "../gradebook-api/src/main/java"
}
After: BUILD SUCCESSFUL

Related

gradle default configuration, what is it and how can I define it

I am having a weird error, for which I found a lot of hits in google but most about android studio or library imports and I don't use android studio nor am I trying to build any app/library so I'll try and ask here and see if I understand the background of it.
I have a project in which I have this plugin:
https://gitlab.com/zkovari/gradle-mermaid-plugin/-/blob/master/examples/single-project/build.gradle
This is a plugin that displays my dependencies as a mermaid graph.
Everything was fine until today I updated some dependencies and created a sub-project to do something else.
I'm trying to generate the graph again and somehow it's failing with this error message.
> Task :generateMermaidDependenciesDiagram FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':generateMermaidDependenciesDiagram'.
> Configuration with name 'default' not found.
I can see in the source code of the plugin that it automatically sets some configurations
#Override
public void apply(Project project) {
GenerateMermaidDependenciesDiagram generateDependencyDiagramsTask = project.getTasks()
.create(GENERATE_MERMAID_DEPENDENCIES_DIAGRAM_TASK_NAME, GenerateMermaidDependenciesDiagram.class);
generateDependencyDiagramsTask.setConfiguration("default");
generateDependencyDiagramsTask
.setOutput(project.getBuildDir().toPath().resolve("mermaid/dependencies.mmd").toFile());
generateDependencyDiagramsTask.setDiagramGenerator(new MermaidDiagramGenerator());
}
So my question is a bit high level but what is the "default" configuration?
And in my project I don't really have any configuration block I simply have my dependencies:
dependencies {
implementation group: 'com.amazonaws', name: 'aws-java-sdk-s3', version: awsVersion, transitive: false
...
testCompile group: 'org.slf4j', name: 'slf4j-simple', version: slf4jVersion
}
My structure looks like this:
project:
-- build.gradle
-- settings.gradle
-- sub-project:
--- build.gradle
I think this stopped working when I added my sub-project but the plugin is applied at the root project level.
I do have a dependency between my sub-project and my root project (one of my sub-project tasks depends on the root project)
I'm trying to understand that this might be very similar but I'm not fully getting it.
Gradle: What Is The Default Configuration and How Do I Change It
I do apply the java plugin on my main project so I expect the configuration.default should exist.
Even if I think I shouldn't do it I tried to re-define a default configuration extending implementation but that did not work
https://docs.gradle.org/current/userguide/declaring_dependencies.html
configurations {
default.extendsFrom implementation
}
build file 'C:\dev\repo\connector-custom\build.gradle': 66: unexpected token: default # line 66, column 5.
default.extendsFrom implementation
I did a quick test and removing my subproject did work so I know the problem is there but no idea why.
It means somehow I must pass to my subproject the default configuration of the main project?

Gradle project test depends on another project's test

This might be a duplicate somewhere but some of the answers were for old Gradle which doesn't work anymore. Please let me know if this is doable. I have a new project named NewProject . NewProject depends on common project which lives in another directory.
- NewProject
- \build.gradle
- \settings.gradle
- \src
- \main\java
- \test\java
- common
- \build.gradle
- \settings.gradle
- \src
- \main\java
- \test\java
In NewProject, my file settings.gradle looks like this
rootProject.anme = 'NewProject'
include ':common'
project(':common').projectDir = file('../common')
and my file build.gradle has below lines in dependencies section
dependencies {
implementation project(':common')
...
testImplementation project(':common')
...
}
The problems I have are two:
Because I don't own the common project code, so I can not change the build file in common.
My test in NewProject couldn't locate the common's test classes. For example BaseTest etc.
I have tried approaches of:
Using testImplementation project(':common:test') doesn't work because ':common:test' is not recognized.
Using testImplementation project(':common').sourceSets.output.classes, but this approach is invalid for Gradle 5.0 and above.
Please let me know if there are other ways of doing this!
What is needed ?
The test-classes and test-resources dir of :common need to be in the classpath of the :newProject test
A way for your setup via Local dir access - in the :newProject build.gradle
testImplementation files('../common/build/classes/java/test')
testImplementation files('../common/build/resources/test')
note: this does not transitively add :common test dependencies to :newProject test, you have to do that manually.

How to exclude specific jars when using gradle in IntelliJ

I think there is a function to exculde from the pop-up menu by right-clicking on the screen below.
And I added my own build.gradle like below, but the dependency I want is not removed.
dependencies {
compile ('org.springframework.boot:spring-boot-starter-data-jpa:2.0.5.RELEASE') {
exclude group: 'org.apache.logging', module: 'log4j-to-slf4j'
}
....
....
}
Is that right?
Seems you missed "log4j" at the end of group name: "exclude group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j' "

How can i have a property in the compile group gradle file

Hi I want to use a gradle property in my gradle build file like this:
compile group: 'org.hibernate', name: 'hibernate-core', version: '${hibernateVersion}'
and i have in the gradle.properties this entry
hibernateVersion:5.2.6.Final
But each time it gives me error:
Could not create an instance of type org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency_Decorated
Try:
compile "org.hibernate:hibernate-core:$hibernateVersion"

Gradle configuration/dependency syntax

I am struggling to understand the gradle groovy syntax for dependencies and what is going on behind the scenes. As a starter I don't see what is exactly happening in this code snippet ....
dependencies {
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
}
What I (hope to) understand (please correct if I am wrong):
dependecies is a method of the org.gradle.api.Project interface /
org.gradle.api.internal.project.DefaultProject class which expects a
Closure to configure the dependencies of the project.
compile is a org.gradle.api.artifacts.Configuration which has been added by the org.gradle.api.plugins.JavaPlugin
What I don't understand:
What exactly is happening by specifying group: 'commons-collections', name: 'commons-collections', version: '3.2' ?
Does this invoke some magic method of the compile configuration object (if so, which one)?
Are group, name and version named parameters of a method call or are they method calls themselves?
Does this create a new org.gradle.api.artifacts.Dependency instance which is added to the compile configuration?
Gradle (like other tools built with Groovy) makes lots of use of methodMissing(...): http://www.groovy-lang.org/metaprogramming.html#_methodmissing
So what happens in the case of dependencies is that you invoke a method that does not exist. The method name is the name of the configuration, and its arguments are the dependency specification.
methodMissing(...) will be called and this will in turn call one of the add(...) methods of DependencyHandler: https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/dsl/DependencyHandler.html

Resources