I am new to gradle and I am trying to use it for an existing java project.
I have created settings.gradle file in my root directory:
include ':datamodel'
include ':active'
include ':client'
include ':zero'
include ':toall'
and build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
}
}
The build.gradle in datamodel looks like this:
apply plugin: 'java'
sourceSets {
main.java.srcDirs = ['src/main/java']
main.resources.srcDirs = ['src/main/java']
test.java.srcDirs = ['tests/java']
test.resources.srcDirs = ['tests/resources']
}
dependencies {
compile 'com.google.protobuf:protobuf-java:2.5.+'
}
When I run gradle build (version: 2.0) I get this failure
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all dependencies for configuration ':datamodel:compile'.
> Could not find any version that matches com.google.protobuf:protobuf-java:2.5.+.
Required by:
MyRoot:datamodel:unspecified
How can I fix this?
Add
repositories {
mavenCentral()
}
to your build script. Not as a part of buildscript closure where you can define where to look for dependencies required to execute your build script. You can do it in your top-level build.gradle using
allprojects {
repositories {
mavenCentral()
}
}
Try this
compile 'com.google.protobuf:protobuf-java:2.5.0'
More info here
The maven repo looks like
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>2.5.0</version>
</dependency>
You can also try and add jcenter() to dependencies like this
dependencies {
mavenCentral()
jcenter()
}
which will allow to search not only in repo1.maven.org
Related
I walked away from my pet project for a year, and now I'm getting this error:
Could not resolve all artifacts for configuration ':classpath'.
Here is my build.gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.4.10'
repositories {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
maven { url 'https://jitpack.io' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I have a project like this:
module1
src/
build.gradle
module2
src/
build.gradle
build.gradle
settings.gradle
In the root build.gralde I am defining 3rd party dependencies needed by all submodules. However, in intellij the submodules don't seem to recognize the dependencies and won't compile. I've seen this work in the past and can't figure out what I'm doing wrong
Root build.gradle
plugins {
id 'java'
}
group 'com.XXX'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
allprojects {
repositories {
mavenLocal()
mavenCentral()
jcenter()
}
}
dependencies {
...
}
settings.gradle
rootProject.name = 'XXX'
include 'module1'
include 'module2'
module1 build.gradle
plugins {
id 'java'
}
group 'com.XXX'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
I realized I just needed to put the dependencies in the root build.gradle within a "subprojects" block and add the java plugin as well.
subprojects {
apply plugin: 'java'
dependencies {
...
}
}
i am spring boot using gradle build. till yesterday gradle build was run smoothly. But today i got this following error ;
Could not resolve all artifacts for configuration ':classpath'.
Could not find spring-core.jar (org.springframework:spring-core:5.2.0.BUILD-SNAPSHOT:20190328.215418-203).
Searched in the following locations:
https://repo.spring.io/snapshot/org/springframework/spring-core/5.2.0.BUILD-SNAPSHOT/spring-core-5.2.0.BUILD-20190327.205120-195.jar
Could not find spring-jcl.jar (org.springframework:spring-jcl:5.2.0.BUILD-SNAPSHOT:20190328.215418-203).
Searched in the following locations:
https://repo.spring.io/snapshot/org/springframework/spring-jcl/5.2.0.BUILD-SNAPSHOT/spring-jcl-5.2.0.BUILD-20190327.205120-195.jar
this is my build.gradle file
buildscript {
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/snapshot' }
maven { url 'https://repo.spring.io/milestone' }
maven {url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.3.RELEASE")
}
}
plugins {
id 'org.springframework.boot' version '2.2.0.BUILD-SNAPSHOT'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'idea'
group = 'me.namila'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/snapshot' }
maven { url 'https://repo.spring.io/milestone' }
jcenter()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'mysql:mysql-connector-java'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
When visiting the relevant url,what i can see is gradle is searching for 27th march build (spring-jcl-5.2.0.BUILD-20190327.205120-195.jar) while the server has the 28th build spring-jcl-5.2.0.BUILD-20190328.164750-201.jar. how to fix this error? i have added buildscript repositories too. any suggesions?
As Antoniossss said in the comments, this happened because snapshot build failure. To fix it i moved to previous build version of springboot. i did the following changes to the build.gradle file;
id 'org.springframework.boot' version '2.1.3.RELEASE'
changed the '2.2.0.BUILD-SNAPSHOT' to 2.1.3 release. this fixed the error. :)
the buildscript repositories & dependencies are a mess, there's a mismatch:
buildscript {
repositories {
maven { url 'https://repo.spring.io/libs-milestone' }
}
dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:2.2.0.BUILD-SNAPSHOT'
}
}
apply plugin: 'org.springframework.boot'
see the documentation.
Testing fails.
How fix exception?
Here is stacktrace and code:
Could not determine the dependencies of task ':test'.
Configuration with name 'default' not found.
My parent settings.gradle
rootProject.name = 'opti'
include 'web'
build.gradle
allprojects {
repositories {
mavenCentral()
}
group 'com.opti'
version '1.0'
apply plugin: 'java'
apply plugin: 'groovy'
dependencies {
testCompile 'org.codehaus.groovy:groovy-all:2.3.11',
'org.spockframework:spock-maven:0.7-groovy-2.0'
}
}
Tested module settings.gradle
rootProject.name = 'web'
include 'web'
build.gradle
group 'com.opti'
version '1.0'
apply plugin: 'groovy'
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile(project(':web'))
}
#Artur check that first:
https://docs.gradle.org/current/userguide/java_plugin.html
It seems that gradle could not find default configuration for web project.
You could also check if running this command helps
gradle :opti:test
or
gradle :web:test
Im trying to convert my project from Maven build to Gradle. The project currently uses Spring Boot.
In my current maven config, I have
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-hibernate4</artifactId>
<version>${jackson.version}</version>
</dependency>
In the above snippet, the jackson.version property comes from Spring Boot pom. Now, in Gradle, i'm using the Spring Boot plugin and Im trying to use the below snippet of code..
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.4.RELEASE")
}}
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'java'
dependencies {
compile("com.fasterxml.jackson.datatype:jackson-datatype-hibernate4")
}
In above, I'm expecting the spring Boot plugin to insert the version of jackson-hibernate4 module. But, this doesnt happen
Any idea on how to achieve this? My intention is to use the same version of jackson builds across the project.
Thanks!
You can use the dependency management plugin to import Spring Boot's bom and get access to the properties that it specifies.
Here's you original build.gradle file with the necessary changes:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:1.2.4.RELEASE"
classpath "io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE"
}
}
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'
repositories {
mavenCentral()
}
dependencyManagement {
imports {
mavenBom 'org.springframework.boot:spring-boot-starter-parent:1.2.4.RELEASE'
}
}
ext {
jacksonVersion = dependencyManagement.importedProperties['jackson.version']
}
dependencies {
compile("com.fasterxml.jackson.datatype:jackson-datatype-hibernate4:$jacksonVersion")
}
Spring Boot 1.3 will start using the dependency management plugin by default when it'll apply the plugin and import the bom for you.