Jenkins build for project with provided dependencies - jenkins

While I am building Gradle based project via Jenkins I'm getting compilation errors. It occurs because a have several jars in build.gradle file with scope 'provided'. I need this to do not include them into generated jar-file. How can I specify path or smth else to let project build on integration server?
Thanx in advance.
Listing of build file provided
configurations {
provided
}
sourceSets {
main {
java { srcDir 'src/main/java' }
resources { srcDir 'src/main/resources' }
compileClasspath += configurations.provided
}
}
dependencies {
provided 'somelib1'
provided 'somelib2'
provided 'somelib3'
}

Related

SonarQube not showing test Jacoco coverage for JUnit tests in a Gradle multi-project

I would like to show the test coverage of a multiple project Spring boot application build with Gradle 6.0. We currently use JUnit5.
The test coverage shows 0% in SonarQube even though a few first tests exists.
The build.gradle files in the top level project (https://github.com/OpenReqEU/eclipse-plugin-vogella/blob/master/server/build.gradle) has the following input:
plugins {
id "org.sonarqube" version "2.7"
id 'jacoco'
}
repositories {
jcenter()
}
subprojects {
apply plugin: 'jacoco'
apply plugin: 'java'
apply plugin: 'eclipse'
repositories {
jcenter()
maven { url 'https://repo.spring.io/snapshot' }
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local/' }
}
jacocoTestReport {
reports {
xml.enabled true
xml.destination file("${buildDir}/coverage-reports/coverage.xml")
//html.destination file("${buildDir}/coverage-reports")
}
}
ext {
springBootVersion = '2.1.1.RELEASE'
}
sourceCompatibility = 1.8
}
wrapper {
gradleVersion = '6.0'
}
In the Jenkins build we set the following parameters:
sonar.projectKey=eclipse-plugin-vogella
sonar.sources=server/com.vogella.prioritizer.server/src/main,server/com.vogella.prioritizer.server.bugzilla/src/main,server/com.vogella.prioritizer.server.issue.api/src/main
sonar.java.binaries=com.vogella.prioritizer.server/build/classes/java/main,com.vogella.prioritizer.server.bugzilla/build/classes/java/main,com.vogella.prioritizer.server.issue.api/build/classes/java/main
sonar.tests=server/com.vogella.prioritizer.server/src/test,server/com.vogella.prioritizer.server.bugzilla/src/test
sonar.coverage.jacoco.xmlReportsPath=server/com.vogella.prioritizer.server.bugzilla/build/jacoco/test.exec,server/com.vogella.prioritizer.server/build/jacoco/test.exec,server/com.vogella.prioritizer.server.issue.api/build/jacoco/test.exec
The result of the build shows an error:
INFO: parsing [/home/jenkins/workspace/issue-prioritizer/coverage-reports/coverage.xml]
ERROR: Reports path not found or is not a directory: /home/jenkins/workspace/issue-prioritizer/coverage-reports/coverage.xml
I see that each project has a generated ${buildDir}/coverage-reports/coverage.xml file but the root file is empty, which is expected as I did not configure anything related to this.
At some point I added a copy task which copied one of the generated xml files from one project into the root folder but the build job complained that the classes were not matching.
Does anybody know how this issue can be solved? I assume I must add a configuration to add a root coverage.xml file which is the aggregate of the individual ones but I have not found a solution for that.
I also tried to apply the jacoco to the root project but that also failed as the root project is not a Java project.
Need to generate report in xml format. Add the sonar property to the xml path as below.
jacocoTestReport {
reports {
xml.enabled true
}
}
sonarqube {
properties {
property "sonar.java.source", "1.8"
property "sonar.java.coveragePlugin", "jacoco"
property "sonar.jacoco.reportPaths", "build/reports/jacoco/test/jacocoTestReport.xml"
}
}
Run the gradle command with the jacocoTestReport
gradlew sonarqube jacocoTestReport
I managed to create the aggregated coverage.xml file by changing the top level build.gradle to:
plugins {
// id "org.sonarqube" version "2.7"
id 'jacoco'
}
repositories {
jcenter()
}
subprojects {
println name;
apply plugin: 'jacoco'
apply plugin: 'java'
apply plugin: 'eclipse'
repositories {
jcenter()
maven { url 'https://repo.spring.io/snapshot' }
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local/' }
}
jacocoTestReport {
reports {
xml.enabled true
}
}
ext {
springBootVersion = '2.1.1.RELEASE'
}
sourceCompatibility = 1.8
}
// run the build with ./gradlew clean build generateMergedReport
task generateMergedReport(type: JacocoReport) {
dependsOn = subprojects.test
additionalSourceDirs.setFrom files(subprojects.sourceSets.main.allSource.srcDirs)
sourceDirectories.setFrom files(subprojects.sourceSets.main.allSource.srcDirs)
classDirectories.setFrom files(subprojects.sourceSets.main.output)
executionData.setFrom project.fileTree(dir: '.', include: '**/build/jacoco/test.exec')
println executionData;
reports {
xml.enabled true
xml.destination file("../coverage-reports/coverage.xml")
}
}
wrapper {
gradleVersion = '6.0'
}
And changing the Jenkins to build generateMergedReport:
cd server && ./gradlew build generateMergedReport
The SonarQube properties where changed to:
sonar.projectKey=eclipse-plugin-vogella
sonar.sources=server/com.vogella.prioritizer.server/src/main,server/com.vogella.prioritizer.server.bugzilla/src/main,server/com.vogella.prioritizer.server.issue.api/src/main
sonar.java.binaries=com.vogella.prioritizer.server/build/classes/java/main,com.vogella.prioritizer.server.bugzilla/build/classes/java/main,com.vogella.prioritizer.server.issue.api/build/classes/java/main
Unfortunately SonarQube still doesnt find the coverage.xml file.
INFO: parsing [/home/jenkins/workspace/issue-prioritizer/coverage-reports/coverage.xml]
ERROR: Reports path not found or is not a directory: /home/jenkins/workspace/issue-prioritizer/coverage-reports/coverage.xml
Does someone have an idea of what is missing?

Could not resolve all files for configuration gradle build

I want tagsoup jar as dependency for one of my test case which reads a html.
In my build.gradle I have done these changes
asciidoctorj {
version = '1.5.4'
}
repositories {
maven {
url "http://mvn-nexus.my.company:8081/nexus/content/groups/public/"
}
mavenCentral()
}
compile(
'org.codehaus.groovy:groovy-all:2.4.14',
'org.codehaus.groovy.modules.http-builder:http-builder:0.7',
'org.apache.httpcomponents:httpclient:4.5.2',
'org.apache.httpcomponents:httpmime:4.5.2',
'commons-cli:commons-cli:1.2',
'ant:ant:1.7.0',
'com.cloudbees:groovy-cps:1.19',
'org.codehaus.gpars:gpars:1.2.1'
)
testCompile(
'junit:junit:4.12',
'org.codehaus.groovy:groovy-all:2.4.14',
'org.spockframework:spock-core:1.1-groovy-2.4',
'org.mockito:mockito-core:2.12.0',
'com.athaydes:spock-reports:1.4.0',
'org.slf4j:slf4j-api:1.7.13',
'org.slf4j:slf4j-simple:1.7.13',
'com.lesfurets:jenkins-pipeline-unit:1.0',
'org.ccil.cowan.tagsoup:1.2.1'
)
varsCompile sourceSets.main.output
}
But I get the following error in my jenkins build while building this project
What went wrong:
Could not resolve all files for configuration ':testCompileClasspath'.
Could not find org.ccil.cowan.tagsoup:0.9.7:.
Required by:
project :
What am I missing?
You miss the artefact name. Try :
'org.ccil.cowan.tagsoup:tagsoup:1.2.1'

Gradle project / task dependency & JavaScript lib in war

We have just started using Gradle and do have a few (noob) questions - hopefully someone can shed some light on those issues :)
We're using Angular and Grails to build our web-app. We want to be as modular as possible and hence put all the Angular-related artifacts (mainly *.js and *.html files) in a separate project in our Gradle multiproject build.
Our project structure is as follows:
- root
-- build.gradle
-- settings.gradle
|-- web-grails (grails project)
|----- build.gradle
|-- web-js-html (angular / js / html sources)
|----- build.gradle
As a start, we simply want to package web-js-html project accordingly. What we've come up so far (other suggestions very welcome) is to apply a webjars structure to it, i.e. have a .jar file with the required resources under /META-INF/resources. Online, we found the following config that seems to work just fine:
// file :web-js-grails/build.gradle
apply plugin: 'java'
ext {
webjarconfig = [
staticHTMLFilesDir : "${projectDir}/src/main/webfrontend",
baseDir: "META-INF/resources/",
subDir : "webjars/" + deployed_app_name
]
}
configurations {
webjar
}
task webjar(type: Jar, dependsOn: 'jar') {
from(fileTree(webjarconfig.staticHTMLFilesDir)) {
into webjarconfig.baseDir + webjarconfig.subDir
}
outputs.file archivePath
}
artifacts {
webjar(webjar.archivePath) {
type 'jar'
builtBy webjar
}
}
By invoking 'gradle webjar', the jar gets created with the files in the correct place.
Question 1:
What I would have expected is that this jar also gets properly created if I invoke 'gradle build'. As far as I understand, 'gradle build' is a task defined by the java plugin which, at some point, invokes the 'jar' task. Once that 'jar' task is done, I would expect the webjar task to be invoked. But it's not, so clearly I'm missing something. Does it follow that webjar only ever gets executed if explicitly invoked (either from command-line or from within the build.gradle file)?
Now, we would like the webjar to be included in the web-grails war-file. The config of :web-grails/build.gradle is as follows:
apply plugin: "grails"
repositories {
mavenLocal()
maven { url artifactory_url }
}
buildscript {
repositories {
mavenLocal()
maven { url artifactory_url }
}
dependencies {
classpath 'org.grails:grails-gradle-plugin:2.0.1-SNB1'
}
}
grails {
grailsVersion = '2.3.8'
groovyVersion = '2.3.0'
}
dependencies {
bootstrap 'org.grails.plugins:tomcat:7.0.50'
compile project(':web-js-html')
}
After try-and-error and quite a bit of reading, I arrived at this (possibly wrong) conclusion: when I invoke 'gradle build' on :web-grails, then (I assume) :build will also be invoked on the referenced :web-js-html project. I say this because the jar gets re-created in the build/lib folder, but obviously not using the webjar-task. Hence, the resulting jar only contains the MANIFEST.MF only.
Question 2:
Do I use Gradle correctly in that case and am I only overseeing a little thing or is this whole approach questionable? How can I get the :web-js-html jar into the war properly?
Thank you for your help in advance!
Your part where you define the new artifact doesn't make any sense for me. Change
artifacts {
webjar(webjar.archivePath) {
type 'jar'
builtBy webjar
}
}
to
artifacts {
webjar webjar
}
Maybe you should rename either your configuration or your task. However the first webjar is your configuration and the second one your task which creates the new jar.
Note that this will create a new artifact, so you have to give it a different name with
task webjar(type: Jar, dependsOn: 'jar') {
baseName = 'newJar'
from(fileTree(webjarconfig.staticHTMLFilesDir)) {
into webjarconfig.baseDir + webjarconfig.subDir
}
outputs.file archivePath
}
But I think you don't want to create a second jar, but change the original one. In that case your don't have to write a new task, but configure the default jar task like this:
jar {
from(fileTree(webjarconfig.staticHTMLFilesDir)) {
into webjarconfig.baseDir + webjarconfig.subDir
}
outputs.file archivePath
}

IntelliJ IDEA: Gradle indexing files - infinite loop

I'm developing a web application, using Grails 2.2.3 with Ember.js (rc3). I'm using IntelliJ IDEA 12.1 Utlimate as IDE and also the IntelliJ TeamCity CI Server - everything's on Windows 7 Professional SP1. Now I wanted to use Gradle 1.7 to better organize my build tasks (combining Grails, Grunt, testing and so on...) and I expected paradise but all I got was hell...
As soon as I started to use the gradle.build file and started JetGradle in IntelliJ IDEA it started to scan and index files over and over (actually it is still running now - 14 hours and counting), the IDE is blocked and I can't do anything... it's really frustrating.
If it's of any interest, here's my gradle.build:
import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.api.tasks.Exec
import org.grails.gradle.plugin.GrailsTask
buildscript {
repositories {
maven { url "http://my.company.archiva:8080/repository/internal" }
maven { url "http://repo.grails.org/grails/repo" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:2.0.0-SNAPSHOT",
"org.grails:grails-bootstrap:2.2.3"
}
}
apply plugin: "grails"
apply plugin: "base"
repositories {
maven { url "http://my.company.archiva:8080/repository/internal" }
maven { url "http://repo.grails.org/grails/repo" }
}
grails {
grailsVersion "2.2.3"
}
configurations {
all {
exclude module: "commons-logging"
exclude module: "xml-apis"
exclude module: "grails-plugin-log4j"
exclude module: "slf4j-log4j12"
}
test {
exclude module: "groovy-all"
}
compile {
exclude module: "hibernate"
}
compileOnly
}
dependencies {
compile("com.my.company:grails-custom-plugin1:0.1.7#zip")
compile("com.my.company:grails-cusotm-plugin:0.2#zip")
compile("com.my.company:backendapi:1.1")
compile("org.mozilla:rhino:1.7R4")
compile("io.netty:netty:3.3.1.Final")
compile("com.google.protobuf:protobuf-java:2.4.1")
compile("org.grails.plugins:cache:1.0.1")
compileOnly "org.grails:grails-plugin-tomcat:$grails.grailsVersion" // No tomcat-*.jar in the war
bootstrap "org.codehaus.groovy:groovy-all:2.0.5"
}
/*
GRADLE Wrapper
*/
task wrapper(type: Wrapper) {
gradleVersion = '1.7'
}
/*
GRUNT Section
*/
task npm(type: Exec) {
group = "Build"
description = "Installs all Node.js dependencies defined in package.json"
workingDir "web-app"
commandLine = ["npm.cmd", "install"]
inputs.file "package.json"
outputs.dir "node_modules"
}
task production(type: GruntTask) {
gruntArgs = "prod"
}
class GruntTask extends Exec {
private String gruntExecutable = Os.isFamily(Os.FAMILY_WINDOWS) ? "grunt.cmd" : "grunt"
private String switches = "--no-color"
private String workDir = "web-app"
String gruntArgs = ""
public GruntTask() {
super()
this.setExecutable(gruntExecutable)
this.workingDir(workDir)
}
public void setGruntArgs(String gruntArgs) {
this.args = "$switches $gruntArgs".trim().split(" ") as List
}
}
/*
WAR creation
*/
task war(type: GrailsTask) {
command "war"
env "prod"
}
Is anybody out there who is able to help me? I searched the internet up and down but it seems that either nobody is using the combination of Grails, Ember.js, Gradle, IntelliJ IDEA or everything is dead simple and I'm just to stupid to use the tools...
I don't recommend to use the Gradle integration in IDEA 12 as it's too limited. (IDEA 13 will be better.) Instead you can use Gradle's "idea" plugin to generate IDEA files. Not sure how well all of this works together with Grails. Grails' own build tool is deeply integrated with the rest of Grails, and from what I've heard, using anything else means to make compromises. (I don't have first-hand experience though.) There have been plans for Grails to switch over its built-in build tool to Gradle one day.
PS: I'd search the IDEA issue tracker and file an issue if there is none.

How to upload artifact to network drive using gradle?

I am reading this:
http://www.gradle.org/docs/current/userguide/artifact_management.html
to understand how to publish/upload my artifact to a network drive/fileshare which is a requirement (we have a maven repo up and running but some artifacts needs to be dumped on a fileshare). The examples I have found are more focused on deploying to repositories, maven, ivy, etc.
I have a simple eclipse java project that I build using gradle 1.2 with the following build.gradle file:
apply plugin: 'java'
sourceSets {
main {
java {
srcDir 'src'
}
}
test {
java {
srcDir 'test'
}
}
}
repositories {
flatDir {
name "fileRepo"
dirs "file://internal.newtwork.drive/folder/test"
}
}
uploadArchives {
repositories {
add project.repositories.fileRepo
}
}
Where in the gradle docs can I read about how to copy resources to a remote fileshare?
I have tried to update the protocol and the dir attribute based on the below answers but I get this error:
What went wrong:
Execution failed for task ':uploadArchives'.
Could not publish configuration ':archives'.
java.io.FileNotFoundException: /internal.newtwork.drive/folder/test/sample-gradle-java-unspecified.jar (No such file or directory)
The destination is correct so does the flatDir repo not support networkdrives?
You should define the following parameters:
archivesBaseName = 'yourappname'
group = 'your.app.package'
version = '1.0.0'
Your URL doesn't mention a scheme (http:, file:, etc.). I don't know if you can get away with using a file: URL, or whether you need to us a different syntax to specify a directory rather than an HTTP URL, but either way, you'll need to correctly form the URI for the Windows UNC path.
See this question for more details.
It looks like you're crossing your wires. The url would only be part of that ivy repository declaration which you're apparently not using. The filesystem repository would be handled by the flatDir block which is then referenced by the add project.repositories.fileRepo statement. I'd suggest trying the full path in the flatDir dir variable, otherwise the path of least resistance may just be to throw together a simple manual file copy (or other transfer) task which is then added on to the main deploy task you're using.
//Try this,
apply plugin: 'java'
apply plugin: 'maven'
repositories {
maven {
url "$archivaUrl"`enter code here`
credentials {
username = "$userName"
password = "$passWord"
}
}
}
// Dependencies
dependencies {
// specify the lib files at compile and run time
compile fileTree(dir: 'lib', include: ['**/*.jar','*.jar'])
runtime fileTree(dir: 'lib', include: ['**/*.jar','*.jar'])
}
// source path
sourceSets {
main {
java {
srcDirs 'src'
}
}
}
uploadArchives {
repositories {
mavenDeployer {
repository(url: "$archivaUrl") {
authentication(userName: "$userName", password: "$passWord")
}
pom.version = "1.0-SNAPSHOT"
pom.artifactId = "fd-common"
pom.groupId = "com.somename.common"
}
}
}

Resources