In Maven, if I wanted to analyze my project with sonar, I could do:
mvn sonar:sonar
using the 'short' plugin name and goal.
In Gradle, is there a similar way to run plugins, without declaring them in the build.gradle script?
This code works fine:
allprojects {
buildscript {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.5"
}
}
apply plugin: 'java'
apply plugin: 'jacoco'
afterEvaluate { project ->
project.apply plugin: 'org.sonarqube'
}
}
gradle --init-script etc/quality.gradle sonarqube
There isn't currently, but there will be at some point. What you can do is to apply the plugin out-of-band (in some init.gradle).
Related
I want to use the Automatic Restart and Live Reload capability of the Spring Boot Tools by adding the org.springframework.boot:spring-boot-devtools dependency and the LiveReload extension in Chrome. See this https://spring.io/blog/2015/06/17/devtools-in-spring-boot-1-3 for more information. However, this does not work because when I run the bootRun Gradle task from STS or the command prompt the application is started (and available on http://localhost:8080) however the launch of the task never finishes and never passes the 70% / 80% mark. This prevents the Automatic Restart feature.
My gradle file looks like this. The complete source code of this project can be found in GitHub, see https://github.com/marinusgeuze/metjekindnaarbuiten/tree/master/backend/springboot.
==============================================================
buildscript {
ext { springBootVersion = '1.4.3.BUILD-SNAPSHOT' }
repositories {
jcenter()
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath('se.transmode.gradle:gradle-docker:1.2')
}
}
group = 'marinusgeuze'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'docker'
jar {
baseName = 'metjekindnaarbuiten-spring-boot-docker'
version = '0.1.0'
}
repositories {
jcenter()
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.boot:spring-boot-devtools")
compile("com.h2database:h2")
}
Sometime the answer for a problem is very simple. You are completely right. Just go to Project > Debug As > Spring Boot App and it works. Install the LiveReload plugin in Chrome and it works great. Thanks a lot.
Please note: even though this question specifically mentions Bamboo CI and the Gradle ShadowJar plugin, I believe this is a basic Gradle config question at heart, and believe it can be answered by any battle-weary Gradle Guru.
I have a Groovy app that is built with Gradle, where build.gradle is:
apply plugin: 'groovy'
apply plugin: 'maven'
apply plugin: 'application'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'eclipse'
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
group = 'com.me.myapp'
mainClassName = "com.me.myapp.MyAppDriver"
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.0'
}
}
dependencies {
// Omitted for brevity
}
jar {
manifest {
attributes 'Main-Class': mainClassName
}
}
repositories {
mavenLocal()
mavenCentral()
}
shadowJar {
classifier = ''
mergeServiceFiles {
exclude 'META-INF/*.DSA'
exclude 'META-INF/*.RSA'
}
}
artifacts {
archives(file("${buildDir}/libs/myapp-${version}.jar")) {
name "myapp"
classifier ""
builtBy shadowJar
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
And where gradle.properties is:
group=com.me.myapp
version=1.0.0
As you can see, I'm using ShadowJar to produce a self-contained "fat JAR" for my app. When I run gradle clean build shadowJar on my local machine, Gradle produces a build/libs/myapp-1.0.0.jar artifact/archive. However, when this same command is ran from our CI server (Bamboo), Gradle produces a build/libs/MYAPP-KEY-1.0.0.jar artifact/archive, where MYAPP-KEY is the Bamboo "build key" (essentially, a unique key/label identifying the build on the server). If you're clueless as to what I'm talking about, I don't think that really matters. What is important to understand is that Bamboo will check out the source code for myapp to a folder named MYAPP-KEY on the CI server. So locally myapp/ is the root of my project, but on CI MYAPP-KEY is the root of my project.
The main point is that I am not explicitly defining something in my Gradle config, and so it seems that Gradle is using the name of the project root to produce the name of the built JAR. What is this "something" and how/where do I define it? The desired end objective is to produce a build/libs/myapp-1.0.0.jar both locally and on CI.
please, look at https://docs.gradle.org/current/dsl/org.gradle.api.tasks.bundling.Jar.html
you can specify base name or full archive name of jar
add it to your jar section
I am trying to build my project with the following build.gradle file.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath('org.springframework.boot:spring-boot-gradle-plugin:1.2.1.RELEASE')
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'
repositories {
maven {
url 'https://repo.spring.io/milestone'
}
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-data-mongodb:1.2.2.RELEASE')
compile('org.springframework.data:spring-data-mongodb:1.7.0.RC1')
compile('org.springframework.cloud:spring-cloud-spring-service-connector')
compile('org.springframework.cloud:spring-cloud-cloudfoundry-connector')
compile 'org.springframework:spring-test:4.1.5.RELEASE'
compile 'de.grundid.opendatalab:geojson-jackson:1.3'
compile 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.5.1'
compile 'org.apache.httpcomponents:httpclient:4.4'
testCompile('junit:junit')
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
I added the milestone repository because I need the spring-data-mongodb 1.7.0.RC1 dependency. However, there seems to be something wrong with the references of the parent-poms because gradle is unable to fetch the following dependency: org.springframework.data.build:spring-data-parent:1.6.0.RC1
It exits with the following error:
Could not find org.springframework.data.build:spring-data-parent:1.6.0.RC1.
Searched in the following locations:
https://repo.spring.io/milestone/org/springframework/data/build/spring-data-parent/1.6.0.RC1/spring-data-parent-1.6.0.RC1.pom
https://repo.spring.io/milestone/org/springframework/data/build/spring-data-parent/1.6.0.RC1/spring-data-parent-1.6.0.RC1.jar
https://repo1.maven.org/maven2/org/springframework/data/build/spring-data-parent/1.6.0.RC1/spring-data-parent-1.6.0.RC1.pom
https://repo1.maven.org/maven2/org/springframework/data/build/spring-data-parent/1.6.0.RC1/spring-data-parent-1.6.0.RC1.jar
The output of the gradlew build --debug command can be found here: http://pastebin.com/seYRMFQP
The command additionally produced the following output to stdout: http://pastebin.com/atcWQsKF
I already tried to clean my local gradle cache but it did not resolve the problem.
Sorry for the inconvenience, the artifact is currently misplaced in the release repository, though it should be in milestone.
We'll move it to milestone asap. Until that happens please add the release repository url 'https://repo.spring.io/release' to your build.
seems the repositories you defined in your build do not contain the libraries you're looking for. but it seems the lib is available in jcenter. to add jcenter add the following snippet to your build.gradle file:
repositories {
jcenter()
}
cheers,
René
http://blog.jonasbandi.net/2014/03/running-nodejs-applications-on-jvm-with.html describes how to prepare to run Avatar.js project.
For a Avatar.js project some jar and native binaries are at maven repository https://maven.java.net/content/repositories/public/com/oracle/
I'd like to use gradle task to get jars from Maven repository and put into lib folder.
The research show it is possible.
http://forums.gradle.org/gradle/topics/create_a_local_mirror_for_dependencies
http://gradle.1045684.n5.nabble.com/collecting-only-external-dependency-files-td5117615.html#a5680602
Is there some more standard implementation of such task as of April 2014 ?
UPDATE:
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
repositories {
maven {
url "https://maven.java.net/content/repositories/public/"
}
}
dependencies {
compile "com.oracle.avatar-js:avatar-js:0.10.+"
}
task copyLibs(type: Copy) {
from configurations.compile
into 'lib'
}
Sample script:
apply plugin: 'java'
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile 'com.google.guava:guava:16.0.1'
}
task copyLibs(type: Copy) {
from configurations.compile
into 'lib'
}
I have a gradle build file and am not able to execute a build. I am working with old code and the code should be built with 1.0-milestone-7 version since other projects use this version.
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'base'
apply plugin: 'application'
assert gradle.gradleVersion == '1.0-milestone-7'
mainClassName = "my.ClassTest"
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
}
test {
systemProperties = System.properties
}
c:\work\gradletest\> gradle clean
FAILURE: Could not determine which tasks to execute.
* What went wrong:
Task 'clean' not found in root project 'gradletest'.
* Try:
Run gradle tasks to get a list of available tasks.
Anything I forgot?
Changing the filename to build.gradle solves the issue. Note that this is the case in 1.0-milestone-7.