I have a multi-module project which uses Gradle. The two that are related to the issue at hand are manray-gradle-plugin which is a Gradle plugin project, providing a single code-generating task, and manray-core which is a plain Java library project which requires the aforementioned plugin to generate some code.
Now, for some reason, I can't compile the plugin project anymore. It gives the following error:
Could not find manray:manray-core:1.0
Searched in the following locations:
<Long list of locations here>
Required by:
project : > manray:manray-gradle-plugin:1.0
...which is weird because the plugin project doesn't reference the core project at all.
The plugin project's build.gradle is like this:
apply plugin: 'java-library'
apply plugin: 'maven'
dependencies {
compile gradleApi()
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.squareup:javapoet:1.9.0'
compile 'com.github.javaparser:javaparser-core:2.5.1'
compile 'org.reflections:reflections:0.9.10'
compile 'io.github.lukehutch:fast-classpath-scanner:2.0.3'
}
sourceCompatibility = "1.7"
targetCompatibility = "1.7"
And the core project's build.gradle is like this:
apply plugin: 'java'
apply plugin: "manray-gradle-plugin"
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
ext {
manrayOutputDir = file("$buildDir/generated-sources/manray/")
}
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
sourceSets.main.java.srcDirs = ["src/"]
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
processComponents {
generatedSourcesDirectory = manrayOutputDir
classpath = sourceSets.main.compileClasspath
}
compileJava.dependsOn processComponents
Finally, the whole project's build.gradle is like this:
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
jcenter()
}
dependencies {
classpath 'manray:manray-gradle-plugin:+'
}
}
allprojects {
apply plugin: "idea"
version = '1.0'
ext {
appName = "Manray"
}
repositories {
mavenLocal()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
}
Also, the settings.gradle looks like this:
include ':manray-gradle-plugin', ':manray-core'
What could cause the build to fail? I've tried cleaning the project, invalidating the gradle caches... Nothing seems to work here.
Related
I am trying to accomplish a Java Spring course at Coursera and downloaded the project with this gradle file.
buildscript {
ext {
springBootVersion = '2.1.0.RELEASE'
}
repositories {
maven { url "https://repo.spring.io/libs-snapshot" }
mavenLocal()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.0.2.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'
sourceCompatibility = 1.8
targetCompatibility = 1.8
war {
baseName = 'gs-convert-jar-to-war'
version = '0.1.0'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/libs-snapshot" }
maven { url "http://maven.springframework.org/milestone" }
flatDir {
dirs 'lib'
}
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-actuator")
compile("org.springframework.boot:spring-boot-starter-aop")
compile("org.springframework.boot:spring-boot-starter-test")
compile("org.springframework.boot:spring-boot-starter-jetty")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.data:spring-data-rest-webmvc")
compile("org.apache.httpcomponents:httpclient:4.5.6")
compile("org.hsqldb:hsqldb")
compile("com.google.guava:guava:17.0")
compile("org.apache.commons:commons-lang3:3.3.2")
compile("com.squareup.retrofit:retrofit:1.6.0")
compile("commons-io:commons-io:2.4")
compile("com.github.davidmarquis:fluent-interface-proxy:1.3.0")
compile(":mobilecloud.handin:1.0.0")
compile(":video.up.test:1.0.0")
compile(":autograder.handin:1.0.0")
compile(":autograder.spec:1.0.0")
testCompile("junit:junit")
}
Unfortunately, I have this error in IntelliJ Idea :
A problem occurred configuring root project 'mobile-cloud-asgn1'.
> Failed to notify project evaluation listener.
> org.gradle.api.tasks.SourceSetOutput.getClassesDir()Ljava/io/File;
I am quite a newbie to Java and Gradle and never faced errors like this, so I have no idea how to fix it. Can anyone help me?
P.S. Repository with project template: https://github.com/juleswhite/mobile-cloud-asgn1
When attempting to use outside dependencies within a custom gradle plugin I'm building, I am not able to import or use them in any regard.
I've attempted to specify in both the build script and the normal dependencies closure my dependencies. I'm using Gradle 5.5 (wrapper script) and I am using the buildSrc method of writing a custom gradle plugin.
// Necessary if loading custom plugins
apply plugin: 'java-gradle-plugin'
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.google.code.gson:gson:2.8.5'
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
group 'com.foo'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
}
gradlePlugin {
plugins {
greeterPlugin {
id = 'com.foo.dbcreation-plugin'
implementationClass = 'com.foo.dbcreation.DbCreation'
}
}
}
dependencies {
compile 'com.google.code.gson:gson:2.8.5'
}
There are quite a few issues I see here.
buildscript does not control the dependencies for your plugin implementation.
Use the plugins {} DSL block to apply plugins. It is the preferred way: https://docs.gradle.org/current/userguide/plugins.html#sec:plugins_block
Should be using implementation over compile since compile is deprecated as noted in https://docs.gradle.org/current/userguide/java_plugin.html#tab:configurations
With that said, your Gradle file should be like:
plugins {
id 'java-gradle-plugin'
id 'eclipse'
id 'idea'
}
group 'com.foo'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
}
gradlePlugin {
plugins {
greeterPlugin {
id = 'com.foo.dbcreation-plugin'
implementationClass = 'com.foo.dbcreation.DbCreation'
}
}
}
dependencies {
implementation 'com.google.code.gson:gson:2.8.5'
}
I figured out what my issue was. For projects being built using the buildSrc directory, you need to have the build.gradle file reside in that directory instead of the root project directory (where the build.gradle normally lives). I just converted the project to a normal gradle project and it works just fine.
I would like to know what am I doing wrong in the Lombok setup for Android Studio 3.0 Beta 2?
That's how my Gradle build file looks like:
buildscript {
repositories {
mavenCentral()
jcenter()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "io.franzbecker:gradle-lombok:1.10"
classpath 'com.android.tools.build:gradle:2.3.3'
}
}
allprojects {
apply plugin: "eclipse"
apply plugin: "idea"
version = '1.0'
ext {
appName = "MyAppName"
gdxVersion = '1.7.0'
}
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
}
project(":desktop") {
apply plugin: "java"
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
}
}
project(":android") {
apply plugin: "android"
configurations { natives }
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
}
}
project(":core") {
apply plugin: "io.franzbecker.gradle-lombok"
apply plugin: "java"
dependencies {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
compileOnly "org.projectlombok:lombok:1.16.18"
}
}
tasks.eclipse.doLast {
delete ".project"
}
I have installed the lombok plugin, and lombok stuff also shows up properly in the IDE, but when I want to build the project Gradle can not find the getters/setters created by Lombok. I tried to follow the tutorials from https://projectlombok.org/setup/android and other stack overflow pages about this setup, but nothing worked. In Android Studio 2.3 I couldn't even enable the annotation processing properly, that's why I updated to the latest beta version, where that at least works.
I have the same issue. At last I end up with this solution -
compileOnly 'org.projectlombok:lombok:1.16.18'
compileOnly 'javax.annotation:javax.annotation-api:1.3.1'
annotationProcessor 'org.projectlombok:lombok:1.16.18'
You need to use new annotationProcessor instead of apt : Gradle migration annotationProcessor
annotationProcessor "org.projectlombok:lombok:1.16.18"
I had the same problem as you and now it works.
I was facing the same issue where upgrading AS to 3.0 and Gradle to 4.1, lombok stopped generating setters/getters.
So If you are using lombok plugin with IntelliJ then for me downgrading lombok from latest stable edge release to 0.15.17.2 solved it.
This issue helped me solving it
This is my file hierarchy, 'Domain Module' has no code right now, basically a wrapper for DBController and Domain.
Domain Module
.gradle
.idea
build
DBController
build
src
main
java
interfaces
IDBController.java
DBController.java
res
some SQL files
test
java
some test files
build.gradle
Domain
.gradle
build
gradle
src
main
java
Server.java
build.gradle
gradlew
gradlew.bat
settings.gradle
gradle
build.gradle
gradlew
gradlew.bat
settings.gradle
This is my build.gradle in Domain Module/build.gradle
group 'Group'
version '1.0-SNAPSHOT'
apply plugin: 'java'
targetCompatibility = 1.8
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile project(':Domain')
compile project(':DBController')
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
}
this is build.gradle in DOmain Module/DBController/build.gradle
group 'Group'
version '1.0-SNAPSHOT'
apply plugin: 'java'
compileJava {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'org.postgresql:postgresql:9.3-1103-jdbc3'
}
}
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
}
dependencies {
compile('com.googlecode.json-simple:json-simple:1.1.1')
compile files('libs/json-simple-1.1.1.jar')
compile('org.postgresql:postgresql:9.3-1103-jdbc3')
}
And finally, build.gradle in Domain Module/Domain/build.gradle
group 'Group'
version '1.0-SNAPSHOT'
buildscript {
repositories {
mavenCentral()
jcenter()
}
}
apply plugin: 'java'
apply plugin: 'idea'
repositories {
mavenCentral()
jcenter()
}
sourceCompatibility = 8
targetCompatibility = 8
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
dependencies {
compile project(':DBController')
}
My main method is in Server.java, and it uses an instance of DBController. How do i assign this file in my java manifest? I've tried the simple
jar {
manifest {
attributes 'Main-Class': 'Domain.src.main.java.Server'
}
but whenever i try to execute java -jar -the generated jar in Domain Module/build/libs-
i get an error telling me it can't find the main file, and as the build gradles are now it gives me an error saying there's no reference to a main class at all.
The gist of my project is that DBController issues queries against a SQL server, and that Server.java will be a spring server. I decided to use gradle to do this so i would learn, and while i have learned alot about gradle, there is still much uncertainty.
I just figured out what was wrong.
jar {
manifest {
attributes 'Main-Class': '-insert main class here-'
}
}
This attribute assumes you're in the src/main/java dir to begin with, so if my filepath was
src/main/java/robert/util/Class.java
i would just have to say
jar {
manifest {
attributes 'Main-Class': 'robert.util.Class'
}
}
Spent so much time solving such a trivial error. My tip for anyone else is to not overlook the 'intro to gradle' sites and such. The solution was there all along.
I'm very new to whole tomcat/spring/eclipse world.
I used gradle a little bit for android projects.
This is a project with tomcat/spring/eclipse and I 'd like to build it with gradle.
I copied a build.gradle file from one of tutorial on the web.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.5.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'gs-serving-web-content'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.7
targetCompatibility = 1.7
dependencies {
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
testCompile("junit:junit")
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
Now I run > gradle build and I see tons of errors which says 'org.springframework.*** does not exist'
I guess I need to somehow tell gradle to include *.jar files under
WebContent/WEB-INF/lib directory, but don't know how.
Please let me know if need to supply more info.
To add all jar files from WebContent/WEB-INF/lib and subfolders you must include the first line:
dependencies {
compile(fileTree(dir: "WebContent/WEB-INF/lib", include: "**/*.jar"))
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
testCompile("junit:junit")
}