I've a multiple module gradle project.
Root has the following modules : core, app (dependent on core), web(dependent on app,core)
From https://plugins.gradle.org/plugin/io.spring.dependency-management
I have used
plugins { id "io.spring.dependency-management" version "0.5.4.RELEASE" }
dependencyManagement {
imports {
mavenBom 'io.spring.platform:platform-bom:+' // 2.0.1.RELEASE
}
}
inside the build.gradle of core.
When I triggered
gradle clean build
from root command prompt, core jar was built successfully, but app failed to resolve the versions of the dependencies.
common.gradle in root directory
repositories {
mavenCentral()
maven { url "http://repo.grails.org/grails/repo/" }
// mavenLocal()
}
build.gradle of Core
plugins {
id "io.spring.dependency-management" version "0.5.4.RELEASE"
}
apply from: '../common.gradle'
apply plugin: 'java'
dependencyManagement {
imports {
mavenBom 'io.spring.platform:platform-bom:+' // 2.0.1.RELEASE
}
}
dependencies {
compile 'javax.jms:javax.jms-api:+' //2.0
compile 'javax.mail:mail:+' //1.4.6
compile 'javax.validation:validation-api' //1.0.0.GA
compile 'org.springframework.security:spring-security-ldap' //4.0.1.RELEASE
compile 'org.springframework.data:spring-data-jpa' //1.9.1.RELEASE
compile 'org.hibernate.javax.persistence:hibernate-jpa-2.0-api:+' //1.0.0.Final
}
build.gradle for app module
apply plugin: 'java'
apply from: '../common.gradle'
dependencies {
compile project(':Core')
compile 'org.hibernate:hibernate-validator' //5.1.1.Final
compile 'net.sf.ehcache:ehcache' //2.9.1
compile 'org.springframework:spring-jms' //4.2.3.RELEASE
compile 'org.springframework:spring-oxm' //3.0.4.RELEASE }
Error message snippet:
FAILURE: Build failed with an exception.
What went wrong:
Could not resolve all dependencies for configuration ':app:compile'.
Could not find org.hibernate:hibernate-validator:.
Searched in the following locations:
https://repo1.maven.org/maven2/org/hibernate/hibernate-validator//hibernate-validator-.pom
https://repo1.maven.org/maven2/org/hibernate/hibernate-validator//hibernate-validator-.jar
http://repo.grails.org/grails/repo/org/hibernate/hibernate-validator//hibernate-validator-.pom
http://repo.grails.org/grails/repo/org/hibernate/hibernate-validator//hibernate-validator-.jar
Required by:
Root:app:unspecified
Environment :
D:\personal>gradle -v
Gradle 2.9
Build time: 2015-11-17 07:02:17 UTC
Build number: none
Revision: b463d7980c40d44c4657dc80025275b84a29e31f
Groovy: 2.4.4
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM: 1.8.0_20 (Oracle Corporation 25.20-b23)
OS: Windows 7 6.1 amd64
You should add the dependency management plugin to the app module. Right now it's only available in the core module, but you are trying to use it's features in the app module.
It's probably a good idea to apply the plugin to every module. If you want you can add this to your root build.gradle:
buildscript {
repositories { mavenCentral() }
dependencies { classpath "io.spring.gradle:dependency-management-plugin:0.5.4.RELEASE" }
}
allprojects {
apply plugin: "io.spring.dependency-management"
}
Answer to the comment:
Artifacts require explicit version when they are not part of the platform-bom. You can declare your own dependencies and use them without explicit version:
dependencyManagement {
dependencies {
dependency 'org.springframework:spring-core:4.0.3.RELEASE'
dependency group:'commons-logging', name:'commons-logging', version:'1.1.2'
}
}
dependencies {
compile 'org.springframework:spring-core'
}
source: plugin documentation
Related
How to understand following build.gradle script:
buildscript
{
repositories {
jcenter()
}
dependencies {
classpath 'com.bmuschko:gradle-tomcat-plugin:2.4.1'
}
}
According to my understanding repositories{} defines dependencies{} locations.
I see that dependencies wrapped inside of buildscript defines tomcat plugin. But what is idea to do so in such strange way?
Whole script:
apply plugin: 'com.bmuschko.tomcat'
apply plugin: 'eclipse-wtp'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.bmuschko:gradle-tomcat-plugin:2.4.1'
}
}
dependencies {
def tomcatVersion = '8.0.46'
tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
"org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}",
"org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}"
api 'org.apache.commons:commons-math3:3.6.1'
}
tomcat {
httpPort = 8080
enableSSL = true
contextPath = '/library-spring'
}
Nowadays almost all plugins for Gradle are published to the Gradle Plugin Portal, so Gradle knows how to resolve them and you can simply use the plugins block to define them in your build script:
plugins {
id 'com.bmuschko.tomcat' version '2.5'
}
In earlier days of Gradle, plugins could only be distributed in the same way as any other library, e.g. using a public Maven repository like Maven Central or Bintray. This way they could be resolved in the same way as other libraries, using the dependencies block to define what to resolve and using the repositories block to define where to resolve.
The problem of using the regular repositories and dependencies blocks is, that those dependencies are loaded when the build script gets evaluated. But to evaluate the build script, the plugin libraries are required to be on the classpath.
For this reason, the buildscript block was introduced to load all the dependencies before evaluating the actual build script. This is also the reason why the buildscript block should always go first in a build script:
buildscript {
repositories {
// where to resolve dependencies of your build script
}
dependencies {
// what dependencies to resolve for your build script
}
}
repositories {
// where to resolve dependencies of your project code
}
dependencies {
// what dependencies to resolve for your project code
}
I am trying to setup error prone using gradle, however everything ive tried gives me some kind of error:
To test I have setup a simple hello world java program using gradle, which without error prone compiles fine.
Then I read: https://github.com/tbroyer/gradle-errorprone-plugin
found from the install guide and tried this in the build.gradle:
plugins {
id 'java'
id("net.ltgt.errorprone") version "2.3.3"
}
group 'test'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
errorprone("com.google.errorprone:error_prone_core:2.3.3")
}
This gave me this error:
Plugin [id: 'net.ltgt.errorprone', version: '2.3.3'] was not found in any of the following sources:
Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
Plugin Repositories (could not resolve plugin artifact 'net.ltgt.errorprone:net.ltgt.errorprone.gradle.plugin:2.3.3')
Searched in the following repositories:
Gradle Central Plugin Repository
I changed 2.3.3 to latest.version and got the same error
Then I found this https://plugins.gradle.org/plugin/net.ltgt.errorprone and tried version number 0.8.1.
I need to be able to use java11 so can't use gradle 4.x as far as I understand.
Also if anybody knows of an actual repository that has used error prone with gradle that I could look at I would be very grateful :)
My gradle wrapper properties is set to use gradle version 5.4.1
Solved as below
Add Gradle plugin to build.gradle file
plugins {
id("net.ltgt.errorprone") version "1.1.0"
}
Release versions
Add dependency to error_prone_core in build.gradle file
dependencies {
errorprone("com.google.errorprone:error_prone_core:2.3.3")
}
Releases
3. Build project, this will add errorprone configuration namespace
4. If you are using java-8, need to add additional dependency too.
errorproneJavac("com.google.errorprone:javac:9+181-r4173-1")
along with dependency in step-2.
5. you can customize/enable/disable it by tasks
tasks.withType(JavaCompile).configureEach {
options.errorprone.disableWarningsInGeneratedCode = true
options.errorprone.enabled = false // change it to true to enable
}
Note: As mentioned in OP comment by #jb-nizet, gralde plugin and error_prone_core has different versions and independent release cycles.
my build.gradle file
buildscript {
ext{
errorproneVersion = '2.3.3'
}
repositories {
mavenLocal()
mavenCentral()
}
}
plugins {
id "java"
id("net.ltgt.errorprone") version "1.1.0"
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
errorprone("com.google.errorprone:error_prone_core:$errorproneVersion")
errorproneJavac("com.google.errorprone:javac:9+181-r4173-1")
}
tasks.withType(JavaCompile).configureEach {
options.errorprone.disableWarningsInGeneratedCode = true
options.errorprone.enabled = false
}
Ref
Github-error-prone
I'm trying to build a jar for a custom gradle plugin to be used by other gradle projects. I'm using java to write the plugin. I'm having a problem including dependencies in my jar. If I build the jar using the below build.gradle
plugins {
id 'groovy'
}
repositories{
mavenCentral()
}
dependencies {
compile gradleApi()
compile localGroovy()
compile 'com.google.guava:guava:27.0-jre'
testCompile 'junit:junit:4.12'
//compile 'org.apache.commons:commons-lang3:3.8.1'
}
group = 'com.mine'
version = '1.0'
I get a NoClassDefFound exception for guava classes when applying the plugin on a project. If I include a task to create a jar with dependencies like below in the build.gradle
jar {
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it)}
}
}
It says Plugin with Id 'my-plugin' not found. How do I include dependencies in a gradle plugin jar?
Your plugin project should be configured as a standalone Plugin project and then published to a maven repository, which will make dependencies resolution work; there is good documentation about writing custom plugin here, specially the following part : using Gradle plugin development plugin
There is also a good example of writing/publishing/consuming a custom Plugin in the Gradle examples here : https://github.com/gradle/gradle/tree/master/subprojects/docs/src/samples/plugins (see the two subprojects publishing and consuming )
And here is a working example with a plugin that has dependency on external library (commons-lang for example):
Plugin project
build.gradle
plugins {
id 'java-gradle-plugin'
id 'groovy'
id 'maven-publish'
}
group 'org.gradle.sample.plugin'
version '0.1'
// pugin metadata configuration
gradlePlugin {
plugins {
myplugin {
id = "org.gradle.sample.plugin.myplugin"
implementationClass = "org.gradle.sample.plugin.MyPlugin"
}
}
}
// publish to local maven repo for testing
publishing {
repositories {
maven {
url "../repos/maven-repo"
}
}
}
// repo for dependences resolution
repositories{
jcenter()
}
// dependencies of this plugin
dependencies {
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.8.1'
}
Plugin implementation : src/main/groovy/org/gradle/sample/plugin/MyPLugin.groovy
package org.gradle.sample.plugin
import org.apache.commons.lang3.StringUtils
import org.gradle.api.Plugin
import org.gradle.api.Project
class MyPlugin implements Plugin<Project> {
#Override
void apply(final Project project) {
println "Applying custom plugin... "
project.tasks.create('testPlugin'){
doLast{
println " custom plugin task executing."
println "Result: " + StringUtils.capitalize("stringtotest")
}
}
}
}
Build and publish this plugin ./gradlew publish : the plugin jar and "plugin marker artefacts" will be published to local maven repo in ../repos/maven-repo
Consumer project
build.gradle
plugins {
id 'java'
// import/apply your custom plugin
id 'org.gradle.sample.plugin.myplugin' version '0.1'
}
group 'org.gradle.sample.plugin'
version '0.1'
repositories{
maven {
url "../repos/maven-repo"
}
jcenter()
}
To test the plugin, try to execute the plugin task testPlugin
> Task :testPlugin
custom plugin task executing.
Result: Stringtotest
Sorry to add this as an answer but I don't have enough points to comment (yes it is a bit late in coming but I found this in a search and it came so close, maybe this will help someone else).
The answer by #M.Ricciuti is correct, just missing one file, namely a settings.gradle in the referencing project (not the plugin) directory:
pluginManagement {
repositories {
maven {
url '../repos/maven-repo'
}
gradlePluginPortal()
ivy {
url '../repos/ivy-repo'
}
}
}
Many thanks, I have tried many things that didn't work before finding this, even the examples by gradle didn't work (or more likely I didn't run them correctly). Anyway I merged what I saw in the answers with M. Ricciuti's answer and saw that file in the sample.
My complete project is at https://github.com/reddierocket/sampleGradlePlugin
The readme has instructions to run it. (Note I did not include the wrapper but I am using gradle version 5.3.1.)
I am using OpenSSL for my Java GRPC project which uses gradle.
I read the documetation which mentions that we should make security settings as mentioned in this link.
I have included the osdetector plugin in the build.gradle file.
But when I build the project, gradle is not able to resolve the osdetector plugin and throwing error
> Failed to apply plugin [id 'com.google.protobuf']
> Plugin with id 'osdetector' not found.
My gradle file is as follows:
def neo4jVersion = "2.3.3"
apply plugin: 'application'
apply plugin: 'java'
apply plugin: 'com.google.protobuf'
apply plugin: 'idea'
apply plugin: 'com.google.osdetector'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.7.3'
classpath 'com.google.gradle:osdetector-gradle-plugin:1.4.0'
}
}
protobuf {
protoc {
// The version of protoc must match protobuf-java. If you don't depend on
// protobuf-java directly, you will be transitively depending on the
// protobuf-java version that grpc depends on.
artifact = "com.google.protobuf:protoc:3.0.0-beta-2"
}
plugins {
grpc {
artifact = 'io.grpc:protoc-gen-grpc-java:0.12.0'
}
}
generateProtoTasks {
all()*.plugins {
grpc {}
}
}
generatedFilesBaseDir = "$projectDir/src/generated"
}
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
compile 'io.grpc:grpc-all:0.12.0'
compile "org.neo4j:neo4j:${neo4jVersion}"
compile "org.neo4j:neo4j-ogm-core:2.0.1"
compile "org.neo4j:neo4j-ogm-http-driver:2.0.1"
compile 'com.google.apis:google-api-services-storage:v1-rev71-1.22.0'
compile 'com.fasterxml.jackson.core:jackson-core:2.7.3'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.7.3'
compile 'com.fasterxml.jackson.core:jackson-databind:2.7.3'
compile 'io.netty:netty-tcnative-boringssl-static:1.1.33.Fork14:' + osdetector.classifier
}
The compile dependency alone is getting resolved however.
I think I am missing something basic here. Please let me know the solution.
Updated
protobuf-gradle-plugin is not compatible with osdetector-gradle-plugin-1.4.0, since that version changed the name of the plugin. Swapping to version osdetector 1.2.1 should fix the problem.
How to control H2 driver version in Grails/Gradle project?
Having problems with running Grails 3 app with H2 I found this answer: Grails accessing H2 TCP server hangs stating it may be caused by driver version difference.
My IDE reports Grails app uses 1.3.176 version of H2, while my server has 1.4.190. So, I would like to upgrade app's H2, but can't find where it is defined. I sought all project files and found no version definition.
UPDATE
My current build.gradle:
buildscript {
ext {
grailsVersion = project.grailsVersion
}
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath 'com.bertramlabs.plugins:asset-pipeline-gradle:2.5.0'
classpath "org.grails.plugins:hibernate:4.3.10.5"
}
}
plugins {
id "io.spring.dependency-management" version "0.5.2.RELEASE"
}
version "0.1"
group "multipleparentsgrails"
apply plugin: "spring-boot"
apply plugin: "war"
apply plugin: "asset-pipeline"
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: "org.grails.grails-web"
apply plugin: "org.grails.grails-gsp"
ext {
grailsVersion = project.grailsVersion
gradleWrapperVersion = project.gradleWrapperVersion
}
assets {
minifyJs = true
minifyCss = true
}
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencyManagement {
imports {
mavenBom "org.grails:grails-bom:$grailsVersion"
}
applyMavenExclusions false
}
dependencies {
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-dependencies"
compile "org.grails:grails-web-boot"
compile "org.grails.plugins:hibernate"
compile "org.grails.plugins:cache"
compile "org.hibernate:hibernate-ehcache"
compile "org.grails.plugins:scaffolding"
runtime "org.grails.plugins:asset-pipeline"
testCompile "org.grails:grails-plugin-testing"
testCompile "org.grails.plugins:geb"
// Note: It is recommended to update to a more robust driver (Chrome, Firefox etc.)
testRuntime 'org.seleniumhq.selenium:selenium-htmlunit-driver:2.44.0'
console "org.grails:grails-console"
}
task wrapper(type: Wrapper) {
gradleVersion = gradleWrapperVersion
}
You should be able to specify it like any other dependency
runtime "com.h2database:h2:1.4.190"
There are many dependencies which may use H2. grails, hibernate, others.
I would go into your project. Let's say it's $HOME/projects/myproj.
1) Do a dependency report. Pipe it into grep so you don't have to wade through a 1,000 line report, and see what versions of H2 are being used.
cd $HOME/projects/myproj
./gradlew dependencies | grep 'H2'
2) Find the highest version number, and then explicitly include this in your build.gradle to force every dependency to use the most current version:
dependencies {
// all the other dependencies
runtime "com.h2database:h2:1.4.190" // where 1.4.190 is the most
// current version. as i
// type this it is 1.4.191
// according to maven central
}