Gradle war plugin pulls in javadoc and sources - gradle

I have a strange problem. I have a project which creates a war file with some custom inclusions like images etc. So far it looks good. The only problem left is that gradle pulls in source jars/zips and javadoc jars/zip into my WEB-INF/lib/ folder of my war.
I thought it might be a problem with Idea but same results with the command line. I guess it has something to do with the dependency configuration?
I use compile and runtime scopes and my artifacts are resolved from Artifactory.
Can anyone point me to a direction where to fix that?
Update:
When i create a task:
task copyAllDependencies(type: Copy) {
from configurations.runtime
into 'allRuntime'
}
or
task copyAllDependencies(type: Copy) {
from configurations.compile
into 'allCompile'
}
I'll get the sources as well. So it seems that it has something to do with the compile/runtime configuration. They're pulling the sources and javadoc. But why?!
Dependencies are declared like this:
dependencies {
compile group: 'org.drools', name: 'drools-core', version: DROOLS_VERSION
compile group: 'org.drools', name: 'drools-compiler', version: DROOLS_VERSION
...
runtime group: 'net.sourceforge.barbecue', name: 'barbecue', version: '1.5-beta1', ext: 'jar'
...
testCompile group: 'org.fitnesse', name: 'fitnesse', version: '20130531'
...
}

Here's another attempt... a bit hacky but might work
configurations {
tempCompile
tempRuntime
tempTestCompile
}
dependencies {
tempCompile "org.drools:drools-core:${DROOLS_VERSION}"
tempRuntime "net.sourceforge.barbecue:barbecue:1.5-beta1#jar"
tempTestCompile "org.fitnesse:fitnesse:20130531"
...
compile configurations.tempCompile.asFileTree.matching {
exclude '**/*-sources.jar'
exclude '**/*-javadoc.jar'
}
runtime configurations.tempRuntime.asFileTree.matching {
exclude '**/*-sources.jar'
exclude '**/*-javadoc.jar'
}
testCompile configurations.tempTestCompile.asFileTree.matching {
exclude '**/*-sources.jar'
exclude '**/*-javadoc.jar'
}
}

As we discovered in the comments, your dependencies are bringing in javadoc and sources as transitive dependencies. You can possibly exclude these by
configurations.all { Configuration config ->
['com.group1', 'com.group2', ..., 'com.groupN'].each { groupId ->
config.exclude [group: groupId, classifier: 'javadoc']
config.exclude [group: groupId, classifier: 'sources']
}
}
Note: I'm not an ivy user so the selector (classifier: 'javadoc' etc) may need tweaking

Related

In gradle, how to copy a subset of compiled test classes

I tried taking a portion of the compiled test classes of a Gradle project, and put them in a jar file (to create a test case). What happened was, only those classes got compiled out of all test classes. Any idea how to do it right?
Here's my build.gradle:
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}
task testSampleJar(type: Zip) {
archiveName "sample.jar"
from compileTestJava {
include "org/example/samples/**"
}
}
test {
dependsOn(testSampleJar)
}
So what seems to be happening is that by just defining the testSampleJar task, the compileTestJava task gets modified to only compile under org.example.samples package. My intent was to use the outputs of compileTestJava and pick something out of them them.
Thanks,
Uri
OK, figured it out, so the two possible solutions are:
//a global filter
task testSampleJar(type: Zip) {
archiveName "sample.jar"
from compileTestJava
include "org/example/samples/**"
}
Or
//Child specification - notice the parentheses around compileTestJava
task testSampleJar(type: Zip) {
archiveName "sample.jar"
from (compileTestJava) {
include "org/example/samples/**"
}
}
I guess the original code was defining compileTestJava instead of using its output, but I don't have a full grasp of Groovy/Gradle DSL to be certain.

How to override configuration level "transitive = false" for one dependency

I've inherited some code and want to add cucumber to the project, preferably changing as little as possible. But the gradle file has a configuration level setting to stop transitive dependencies being pulled in, which is causing cucumber-java to not pull in cucumber-core and therefore fail.
So here's the relevant parts of build.gradle:
configurations.all {
transitive = false
}
depdendencies {
compile(group: .... lots of these
testCompile(group: 'io.cucumber', name: 'cucumber-java8', version: '4.8.0', transitive: true)
testCompile(group: 'io.cucumber', name: 'cucumber-testng', version: '4.8.0', transitive: true)
}
my hope was that the transitive: true would then override the configuration level but it doesn't work.
I have also tried adding:
configurations {
all*.exclude group: 'io.cucumber', module: 'cucumber-java8'
}
but it then doesn't pull in this dependency at all
I'd prefer not to pull in all the dependencies for cucumber manually, and I'd rather not remove this configuration level transitive = false. Is it possible to do what I'm trying? Can I set the configuration just for compile dependencies? Or will I have to remove the configuration level setting and add transitive: false to every compile dependency?
Thanks for you help
I think you are looking for something like this:
configurations {
compile {
transitive false
}
testCompile {
transitive true
}
}

How can I publish many dependant subprojects in a certain order with gradle?

I'm trying to publish two subprojects with gradle. I have two subprojects: SubprojectA is dependant on SubprojectB. I want to publish them both using maven-publish. I have this in build.gradle:
plugins {
id 'java'
id 'maven-publish'
}
publishing {
publications {
SubprojectA(MavenPublication) {
println(project(':subprojectA').tasks)
groupId group
artifactId 'subjprojectA'
version version
artifact project(':subprojectA').tasks.getByName('jar')
}
SubprojectB(MavenPublication) {
groupId group
artifactId 'subjprojectB'
version version
artifact project(':subjprojectB').tasks.getByName('jar')
}
}
repositories {
maven {
url "http://some-url"
}
}
}
Gradle tries to publish them in alphabetical order: Since subprojectA depends on subprojectB, it doesn't work because subprojectB hasn't been published yet. If I rename subprojectA to ZSubprojectA, like this:
ZSubprojectA(MavenPublication) {
println(project(':subprojectA').tasks)
groupId group
artifactId 'subprojectA'
version version
artifact project(':subprojectA').tasks.getByName('jar')
}
then it works, but I don't like this solution. I've tried something like this:
project(':subprojectA') {
publish.dependsOn(":subprojectB:build")
}
but it doesn't work, and :subprojectB:publish doesn't exist.
I've been able to solve it. This was the problem:
Both subprojects had their respective build.gradle files. In subprojectA's build.gradle there was something like this:
plugins {
id 'java'
}
sourceCompatibility = 1.8
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
implementation group: 'com.neovisionaries', name: 'nv-i18n', version: '1.22'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.1'
implementation group: 'com.myorg.something', name: 'subprojectB', version: '1.0.0-SNAPSHOT'
}
Therefore it was trying to get subprojectB from my organization private repository, and I should have done something like this:
compile project(":subprojectB")
I should have include both build.gradle files in my question. But the problem is solved.

How can I exclude from Gradle dependency lists after the fact?

This is for a Maven-to-Gradle build conversion on a large build. Think Rodan, Ghidora, Godzilla, etc. Yeah. That big.
Given a dependency that looks like this:
ext.jbossBom = [ ... ]// This is in the root project.
compile (rootProject.ext.jbossBom) //This is not in the root project
How can I exclude items from the above? I've tried variants of:
compile (rootProject.ext.jbossBom) {
exclude group: "some.group", module: "some.module"
}
jbossBom is a collection. Remove the element your want to eliminate:
compile (rootProject.ext.jbossBom.findAll{ !it.startsWith('some.group')})
To exclude a certain transitive dependency globally(irrespective of which dependency brings it in), you can do:
configurations {
compile.exclude group: 'commons-math3', module: 'commons-math3'
compile.exclude group: 'commons-pool2', module: 'commons-pool2'
}
To exclude a specific transitive dependency from each of the contents of jbossBom, you can do:
dependencies{
jbossBom.each{
compile (it){exclude group:'foo', module:'bar'}
}
}

Spring-Boot html in /templates don't render from command line

I have read several online posts about this issue, but for some reason none of those helped me solve this. I looked at the spring-boot examples and I don't think I am doing much different than those.
I am using Spring-boot 1.2.1, Thymeleaf, embedded tomcat without issue in IntelliJ. However, when I do a "gradle clean build", move the jar file, and an application.properties file to a deploy directory. I then start on the command with:
java -jar edm-0.1.0.jar
org.thymeleaf.exceptions.TemplateInputException: Error resolving template "/loginPage", template might not exist or might not be accessible by any of the configured Template Resolvers
at org.thymeleaf.TemplateRepository.getTemplate(TemplateRepository.java:245)
I am letting spring-boot configure my site for the most part. I am using the recommended directory structure:
I can hit the index page, and the REST calls seem to work just fine.
UPDATE based upon feedback:
I don't know if this is a broken jar issue, but when I extract it the structure and files appear correct. I can run "gradle bootRun" from the top of my project structure just fine. But if I deploy the jar file and run it, I get an error:
Task 'bootRun' not found in root project 'edm'
Here is my build.gradle file in case there might be an issue in it:
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'jacoco'
apply plugin: 'maven'
idea {
project {
//if you want to set specific jdk and language level
jdkName = '1.8'
languageLevel = '1.8'
}
}
jacoco {
toolVersion = "0.7.0.201403182114"
}
project.ext {
springBootVersion = '1.2.1.RELEASE'
}
configurations {
querydslapt
}
buildscript {
repositories {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
maven { url "http://repo.spring.io/libs-milestone" }
maven { url "http://repo.spring.io/libs-snapshot" }
mavenLocal()
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion")
}
}
jar {
baseName = 'edm'
version = '0.1.0'
}
dependencies {
querydslapt group: 'com.mysema.querydsl', name: 'querydsl-jpa', version: '2.8.0', classifier: 'apt-one-jar', transitive: false
compile("org.springframework.boot:spring-boot-starter-web:$springBootVersion")
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-starter-security")
compile("org.springframework.boot:spring-boot-starter-data-jpa:$springBootVersion")
compile("org.springframework.security:spring-security-web:4.0.0.M1")
compile("org.springframework.security:spring-security-config:4.0.0.M1")
compile('org.thymeleaf.extras:thymeleaf-extras-springsecurity3:2.1.1.RELEASE')
compile('com.android.tools.build:gradle:1.0.1')
compile("org.hibernate:hibernate-core:4.3.4.Final")
compile("org.hibernate:hibernate-entitymanager:4.3.4.Final")
compile("org.hibernate:hibernate-validator")
compile("org.apache.velocity:velocity:1.7")
compile('javax.mail:mail:1.4.1')
compile("org.springframework:spring-context-support")
compile("com.h2database:h2:1.3.172")
compile("joda-time:joda-time:2.3")
compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.5.0")
compile("org.codehaus.groovy.modules.http-builder:http-builder:0.7.1")
compile('org.codehaus.groovy:groovy-all:2.2.1')
compile('org.jadira.usertype:usertype.jodatime:2.0.1')
compile("postgresql:postgresql:9.1-901.jdbc4")
testCompile('org.spockframework:spock-core:1.0-groovy-2.0-SNAPSHOT') {
exclude group: 'org.codehaus.groovy', module: 'groovy-all'
}
testCompile('org.spockframework:spock-spring:1.0-groovy-2.0-SNAPSHOT') {
exclude group: 'org.spockframework', module: 'spock-core'
exclude group: 'org.spockframework', module: 'spring-beans'
exclude group: 'org.spockframework', module: 'spring-test'
exclude group: 'org.codehaus.groovy', module: 'groovy-all'
}
testCompile("org.springframework.boot:spring-boot-starter-test:$springBootVersion")
testCompile('org.codehaus.groovy.modules.http-builder:http-builder:0.7+')
testCompile("junit:junit")
// for the anontation processor
querydslapt group: 'com.mysema.querydsl', name: 'querydsl-jpa', version: '2.8.0', classifier: 'apt-one-jar', transitive: false
// for compiling
compile("com.mysema.querydsl:querydsl-jpa:3.3.3")
compile("com.mysema.querydsl:querydsl-apt:3.3.3")
}
task wrapper(type: Wrapper) {
gradleVersion = '2.0'
}
project.configurations {
providedRuntime
}
project.bootRepackage {
enabled = true
}
I also tried adding some thymeleaf configuration (even though I am not explicitly using Thymeleaf) to my application.properties file:
liquibase.changeLog=classpath:/db/changelog/db.changelog-master.xml
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.check-template-location=true
So I guess my question is, why does running the "java -jar" not let me view the webpages?
It turns out that my REST controllers were proceeded by "/" so login page became "//loginPage" and that was causing the problem. I found the answer here but it took me a while to realize that was the issue. Hopefully this answer will help out someone in the future as it as a bear to figure out.

Resources