Gradle build problem: Could not get unknown property 'libraries' in Caffeine Simulator - gradle

I used to work on my fork of Caffeine’s Simulator using Eclipse, and the project was compiled and built OK.
Suddenly I started getting the following error while running Gradle build:
Could not get unknown property 'libraries' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
I indeed don’t understand the syntax “implementation libraries.X” in Caffeine's Simulator build.gradle dependencies.
To study the problem, I generated the project MWE in Eclipse, with the following build.gradle:
plugins {
id 'java-library'
}
repositories {
jcenter()
}
dependencies {
api 'org.apache.commons:commons-math3:3.6.1'
implementation 'com.google.guava:guava:28.2-jre'
testImplementation 'junit:junit:4.12'
implementation libraries.xz
}
This MWE gives the same error.
Once removing the line implementation libraries.xz
the project builds OK.
I guess that "libraries" is a property / variable defined somewhere in Caffeine, but fail to find it.

The manifest of dependencies is defined in dependencies.gradle. The root build file applies this to all of the subprojects,
subprojects {
apply plugin: 'biz.aQute.bnd.builder'
apply plugin: 'java-library'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply from: "${rootDir}/gradle/publish.gradle"
apply from: "${rootDir}/gradle/codeQuality.gradle"
apply from: "${rootDir}/gradle/dependencies.gradle"
...
}
The central manifest allows for referring to the dependency more abstractly, so that versions can be upgraded globally and reduces copy-and-paste issues.
It sounds like a local change to the build causes it to no longer import the manifest and the property cannot be resolved.

Related

Add Android plugin to gradle init script

I'm currently working on creating my own Gradle custom distribution and I want to add some default settings to all my Android projects. I tried to do this with the following init script:
initscript {
repositories {
mavenCentral()
google()
}
dependencies {
classpath "com.android.tools.build:gradle:7.1.1"
}
}
apply plugin: 'com.android.application'
gradle.allprojects {
android {
...
}
dependencies {
implementation 'junit:junit:4.12'
}
}
but with this I get Plugin with id 'com.android.application' not found. What am I missing here?
For gradle init script, you must use the fully qualified class name of the plugin instead of the id. So you will have to apply the plugin this way:
apply plugin: com.android.build.gradle.AppPlugin
Change the initscript to buildscript.
And also, does this build.gradle in root project/directy? Because you Android Gradle Plugin is applied in the gradle module not in the root.
So apply:
apply plugin: "com.android.application"
inside your module's build.gradle.
Make sure your Gradle version is compatible with your Android Gradle Plugin.
For more information you can follow the link below, if it helps you
plugin with id com.android.application not found

How to solve red-cross overlay on build.gradle file?

There is a red cross overlay on my build.gradle. It is annoying because i am not able to pin-point where it is coming from.
Some information about my project:
1. I am using sts-3.9.8.RELEASE as IDE
2. It is a spring boot project, 2.1.7.RELEASE
3. In gradle-wrapper.properties, i am using v5.5
4. When i run a build or a bootWar task, both tasks run successfully.
5. The rootProject.name in settings.gradle, matches the project name in sts.
6. I can run the spring boot application successfully, and i can access the end-points without any issue.
I have tried deleting the build directory of the project, as i thought there could be some old settings that is upsetting gradle, but no.
I have also tried to right-click on the project, click on Gradle, click on Refresh Gradle Project, to no avail.
I have also tried to refresh the project, but still no, the red cross is still there.
Contents of my build.gradle:
plugins {
id 'java'
id 'org.springframework.boot' version '2.1.7.RELEASE'
}
apply plugin: 'io.spring.dependency-management'
apply plugin: 'eclipse'
apply plugin: 'war'
group = 'com.somename'
//version = '1.0.0'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
jcenter()
}
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
dependencies {
developmentOnly("org.springframework.boot:spring-boot-devtools")
implementation 'org.springframework.boot:spring-boot-starter-web'
...
testImplementation 'org.springframework.security:spring-security-test'
}
Any help or pointers as to what is upsetting gradle is most welcome.
Thanks! :-)
Solution:
Deleting the build directory and re-building was the solution. The red-cross overlay was still visible on my build.gradle, because in the midst of trying things, i changed the gradle version to the latest v5.6.2 and did not notice that an error appeared in the Problems view pane. In short, it said that it can't run a build with that distribution.
New Issue:
~ 2 years later, with v7.1.1, i stumbled upon my own question/answer which did not help me this time. If you are interested, i posted a new question here.

Gradle's com.moowork.gradle.grunt plugin

I have a webapp compilation subproject which is written in a separate script plugin and is being added to the root project via "apply from: scriptSrc" syntax. Top of my script plugin looks like this:
buildscript {
repositories {
jcenter()
}
dependencies{
classpath 'com.moowork.gradle:gradle-grunt-plugin:0.10'
}
}
apply plugin: "com.moowork.grunt"
However its not recognizing the plugin and fails on the initialization phase saying
Plugin with id 'com.moowork.grunt' not found.
I am following this: https://plugins.gradle.org/plugin/com.moowork.grunt/0.10.
Anyone else having issues with grunt plugin inclusion in script plugin?
Not sure exactly what exactly is causing the issue. Make sure you have the buildscript setup the following way.
apply plugin: 'com.moowork.grunt'
buildscript{
dependencies{
classpath 'com.moowork.gradle:gradle-grunt-plugin:0.13'
classpath 'com.moowork.gradle:gradle-node-plugin:0.12'
}
// In this section you declare where to find the dependencies of your project
repositories {
jcenter()
mavenCentral()
}
}
If you go plan to use plugin:0.13, you need to include the node-plugin as well or else you may get a NoClassDefFound Exception. This may not be necessary if you continue to use version 0.10.
Also, if you are working on a gradle project in eclipse and building the project from commandline, make sure you refresh the project so build reflects in your workspace.

Invalid classpath publish/ export dependency /ouat-contract. Project entries not supported

I am trying create an Gradle multi project similar to this structure
ouat-services
- ouat-contract
- ouat-servicesImpl (web project)
I followed the eclipse example and define my ouat-services settings.gradle as
include "ouat-contract", "ouat-servicesImpl"
In my ouat-servicesImpl build-gradle I define
dependencies {
compile project(':ouat-contract')
}
My problem starts when I try apply war plug-in in ouat-servicesImpl, I receive the following message in eclipse problem view:
Invalid classpath publish/ export dependency /ouat-contract. Project entries not supported
My ouat-services build.gradle
configure(subprojects) {
apply plugin: 'com.github.ben-manes.versions'
apply plugin: 'eclipse'
apply plugin: 'java'
version = '1.0'
sourceCompatibility = 1.8
targetCompatibility = 1.8
def defaultEncoding = 'UTF-8'
[compileJava, compileTestJava]*.options*.encoding = defaultEncoding
repositories {
jcenter()
mavenLocal()
mavenCentral()
}
jar {
manifest.attributes provider: 'Company'
}
}
configure(project(':ouat-servicesImpl')) {
apply plugin: 'checkstyle'
apply plugin: 'eclipse-wtp'
apply plugin: 'findbugs'
apply plugin: 'jacoco'
//apply plugin: 'jetty'
apply plugin: 'pmd'
apply plugin: 'war'
}
buildscript {
repositories {
jcenter()
mavenCentral()
mavenLocal()
}
dependencies {
classpath 'com.github.ben-manes:gradle-versions-plugin:0.10.1'
}
}
My ouat-servicesImpl build gradle was changed to:
dependencies {
compile project(':ouat-contract')
cxfArtifacts.each { artifact ->
compile "org.apache.cxf:$artifact:$cxfVersion"
}
springArtifacts.each { artifact ->
compile "org.springframework:$artifact:$springVersion"
}
testCompile "org.testng:testng:$testNGVersion"
testCompile "org.hamcrest:hamcrest-all:$hamcrestVersion"
testCompile "org.springframework:spring-test:$springVersion"
//WAR PLUGIN
providedCompile "javax.servlet:javax.servlet-api:$servletAPIVersion"
runtime "javax.servlet:jstl:$jstlVersion"
}
Is this an eclipse plug-in problem or I am doing something wrong?
Here's the magic steps I've discovered to make it work without messing with Project settings manually.
Run command: gradle cleanEclipse eclipse
as a result of this command Eclipse forgets that the project was supposed to have a gradle nature.
Add gradle nature back to the project by doing Configure -> Convert to Gradle Project.
as a result of this command the error reappears.
if incompatible plugin java version error appears then just delete .settings directory and refresh.
Run command: gradle cleanEclipseClasspath eclipseClasspath
this final step should get it fixed until the next time.
In my case, this was due to mixing "faceted" and non-faceted projects. The projects with the error had been converted to faceted form, and the project they referenced which it was complaining about had not been. You can configure the project to be faceted via use of the eclipse-wtp plugin, by adding this to your ouat-contract gradle file:
eclipse{
wtp{
facet{}
}
}
This will add facets for Java and a utility module when using the java and war plugins (see the EclipseWTPFacet documentation for more information on the defaults and manually adding facets if you aren't using the war plug-in). The utility module part is the key to avoid the error.
Note that within this block you can also access the facet file directly to perform manual XML manipulation if you need to do other things, like specify a particular Apache Tomcat Runtime or or similar
Once you make this change, you can use Eclipse to do Gradle -> Refresh All on ouat-contract within your workspace - once I did this, the error went away
I've also run into this problem long time ago. It really seems to be the problem related to the Eclipse plugin included in "Gradle IDE Pack" (as it works from the command line without problems).
My setup is probably way more complex than Yours (I'm including modules from one top-level gradle project into another top-level gradle project), but to overcome this specific error
Invalid classpath publish/ export dependency /my-project. Project entries not supported
... i excluded project dependency if some specific gradle property was missing:
if(project.hasProperty("myProjectRefAddedFromIDE")) {
println "NB! Build script started with property 'myProjectRefAddedFromIDE' - expecting that this project in IDE is configured to add the direct reference to my-project"
} else {
compile project(':my-project')
}
And to add the property "myProjectRefAddedFromIDE" only from IDE, i have configured eclipse plugin as follows:
Window -> Preferences -> Gradle -> Arguments -> Program arguments -> Use: ´-PmyProjectRefAddedFromIDE´
Just a warning: this will probably work for you, but there might be some other problem with Your setup, as for simple multi-module project (that doesn't include modules form another multi-module project) I don't have to use this workaround.
This works for me to remove the duplicate jar files from JRE System Library.
Steps Right click on Project and go to Build Path->configure build path->Libraries.
Remove the jars that are not in the classpath or duplicated in Maven dependency.

Resolve dependencies for multiple configurations

Code speaks better than words, say I have the following build.gradle:
apply plugin: 'java'
apply plugin: 'eclipse'
configurations {
optionalDependency
}
dependencies {
compile 'group:artifact:1.0'
optionalDependency 'group:artifact:1.2'
}
eclipse.classpath.plusConfigurations += [configurations.optionalDependency]
Eclipse will now get both the 1.0 version and the 1.2 version of the artifact. Is there a way to tell gradle that I do not want both configurations, but rather resolve as though they were one?
Just have one extend the other. If you want the compile configuration to include dependencies in the optionalDependecy configuration then simply do the following.
configurations {
optionalDependency
compile.extendsFrom optionalDependency
}

Resources