We are using Cucumber in our development process in building a service in AWS. We are using DynamoDb and when we are running tests locally we are using a local instance of DynamoDb. To do this we need to include in the classpath certain library files. We have manged to do this for the test task of gradle but not for the cucumber task
Given that these files are in a folder build/dyanamodb-local in our project, is there a way to include them in the classpath of the cucumber task?
The build.gradle file:
plugins {
id 'java'
id 'jacoco'
id 'checkstyle'
id 'pmd'
}
repositories {
jcenter()
maven { url 'https://jitpack.io' }
maven { url "https://s3.eu-central-1.amazonaws.com/dynamodb-local-frankfurt/release" }
}
def jacksonVersion = "2.10.3"
def jupiterVersion = "5.6.0"
def awsSdkVersion = "1.11.791"
apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'checkstyle'
apply plugin: 'pmd'
configurations.testImplementation.canBeResolved = true
configurations {
cucumberRuntime {
extendsFrom testImplementation
}
}
dependencies {
implementation group: 'com.amazonaws', name: 'aws-lambda-java-core', version: '1.2.0'
implementation group: 'com.amazonaws', name: 'aws-lambda-java-events', version: '2.2.7'
implementation group: 'com.amazonaws', name: 'aws-java-sdk-lambda', version: awsSdkVersion
implementation group: 'com.amazonaws', name: 'aws-java-sdk-dynamodb', version: awsSdkVersion
implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jdk8', version: jacksonVersion
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: jacksonVersion
implementation group: 'com.fasterxml.jackson.module', name: 'jackson-module-parameter-names', version: jacksonVersion
implementation group: 'com.github.BIBSYSDEV', name: 'nva-commons', version: '0.3.5'
testImplementation group: 'com.amazonaws', name: 'DynamoDBLocal', version: '1.12.0'
testImplementation group: 'com.almworks.sqlite4java', name: 'sqlite4java', version: '1.0.392'
testImplementation group: 'io.cucumber', name: 'cucumber-java', version: '5.6.0'
testImplementation group: 'io.cucumber', name: 'cucumber-picocontainer', version: '5.6.0'
testImplementation group: 'io.cucumber', name: 'cucumber-junit', version: '5.6.0'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter', version: jupiterVersion
testImplementation group: 'org.hamcrest', name: 'hamcrest', version: '2.2'
}
task copyNativeDeps(type: Copy) {
from(configurations.testImplementation) {
include "*.dylib"
include "*.so"
include "*.dll"
}
into 'build/dynamodb-local'
}
test.dependsOn copyNativeDeps
test.doFirst {
systemProperty "java.library.path", 'build/dynamodb-local'
}
test {
useJUnitPlatform()
failFast = true
testLogging {
events 'skipped', 'passed', 'failed'
}
finalizedBy jacocoTestReport
}
task cucumber() {
dependsOn assemble, compileTestJava
doLast {
javaexec {
main = "io.cucumber.core.cli.Main"
classpath = configurations.cucumberRuntime+ configurations.testImplementation + sourceSets.main.output + sourceSets.test.output
args = ['--plugin', 'pretty', '--glue', 'features', 'src/test/resources']
}
}
}
Edit: I mixed the classpath and the library-path. What I needed, was to edit the library path. If one needs to edit the classpath however, I would suggest to look at the solution provided by #madhead
I assume that you have a configuration for Cucumber, like in the docs:
configurations {
cucumberRuntime {
extendsFrom testImplementation
}
}
Then just add a folder to the configuration like:
dependencies {
cucumberRuntime(fileTree('build/dyanamodb-local'))
}
It should do the trick.
Instead of polluting your dependencies, consider using amazon/dynamodb-local Docker image or LocalStack.
I made it work by adding systemProperties in the javaexec configuration of the cucumber task. The cucumber task is now the following:
task cucumber() {
dependsOn assemble, compileTestJava
doLast {
javaexec {
main = "io.cucumber.core.cli.Main"
systemProperties =[ "java.library.path" :'build/dynamodb-local']
classpath = configurations.cucumberRuntime+ configurations.testImplementation + sourceSets.main.output + sourceSets.test.output
args = ['--plugin', 'pretty', '--glue', 'features', 'src/test/resources']
}
}
}
Related
I got a project and it is built with gradle 6 or older version.
I've checked the other stakeoverflow discussion with compile/testCompile problem in gradle 7, and I change all the dependencies from compile/testCompile to api/testImplementation.
But it still doesn't work when I'm doing gradle build.
It still return with Configuration with name 'compile' not found
I've checked this:
Build error with gradle Could not find method testCompile()
What's the difference between implementation, api and compile in Gradle?
Here is my root gradle configuration:
buildscript {
repositories {
mavenCentral()
}
dependencies {
// https://github.com/google/protobuf-gradle-plugin
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.10'
}
}
plugins {
id 'application'
id 'java'
id 'java-library'
id "com.google.protobuf" version "0.8.10"
}
group 'com.ght'
version '61'
mainClassName = 'com.application'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
// jcenter() is no longer support.
// jcenter()
mavenCentral()
}
sourceSets {
main {
proto {
srcDir 'src/main/protobuf'
include '**/*.protodevel'
}
}
}
dependencies {
testImplementation group: 'junit', name: 'junit', version: '4.12'
implementation group: 'com.google.protobuf', name: 'protobuf-java', version: '3.0.0'
// https://mvnrepository.com/artifact/ch.qos.logback/logback-classic
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.1.3'
// https://mvnrepository.com/artifact/ch.qos.logback/logback-core
implementation group: 'ch.qos.logback', name: 'logback-core', version: '1.1.3'
// https://mvnrepository.com/artifact/org.slf4j/slf4j-implementation
implementation group: 'org.slf4j', name: 'slf4j-implementation', version: '1.7.26'
// https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.2.1'
// https://mvnrepository.com/artifact/org.locationtech.jts/jts-core
implementation group: 'org.locationtech.jts', name: 'jts-core', version: '1.16.0'
// https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.4'
// https://mvnrepository.com/artifact/com.vividsolutions/jts
implementation group: 'com.vividsolutions', name: 'jts', version: '1.13'
// https://mvnrepository.com/artifact/com.google.guava/guava
implementation group: 'com.google.guava', name: 'guava', version: '19.0'
// https://mvnrepository.com/artifact/org.apache.commons/commons-math3
implementation group: 'org.apache.commons', name: 'commons-math3', version: '3.5'
// https://mvnrepository.com/artifact/commons-logging/commons-logging
implementation group: 'commons-logging', name: 'commons-logging', version: '1.2'
}
protobuf {
// Configure the protoc executable
protoc {
// Download from repositories
artifact = 'com.google.protobuf:protoc:3.0.0'
}
generatedFilesBaseDir = "$projectDir/gen"
}
clean {
delete protobuf.generatedFilesBaseDir
}
jar{
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
manifest {
attributes('Manifest-Version': archiveVersion, 'Main-Class': 'com.application')
}
exclude 'logback-test.xml'
exclude '**/schema/**'
exclude '**.proto'
}
Here is build error message:
A problem occurred configuring root project 'application'.
> Configuration with name 'compile' not found.
* Try:
> Run with --info or --debug option to get more log output.
* Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'application'.
at org.gradle.configuration.project.LifecycleProjectEvaluator.wrapException(LifecycleProjectEvaluator.java:84)
at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:77)
at org.gradle.configuration.project.LifecycleProjectEvaluator.access$400(LifecycleProjectEvaluator.java:55)
at org.gradle.configuration.project.LifecycleProjectEvaluator$NotifyAfterEvaluate.run(LifecycleProjectEvaluator.java:255)
.
.
.
Caused by: org.gradle.api.artifacts.UnknownConfigurationException: Configuration with name 'compile' not found.
at org.gradle.api.internal.artifacts.configurations.DefaultConfigurationContainer.createNotFoundException(DefaultConfigurationContainer.java:108)
at org.gradle.api.internal.DefaultNamedDomainObjectCollection.getByName(DefaultNamedDomainObjectCollection.java:333)
at org.gradle.api.internal.artifacts.configurations.DefaultConfigurationContainer.getByName(DefaultConfigurationContainer.java:98)
at org.gradle.api.internal.artifacts.configurations.DefaultConfigurationContainer.getByName(DefaultConfigurationContainer.java:50)
.
.
.
at com.google.protobuf.gradle.ProtobufPlugin$_setupExtractIncludeProtosTask_closure21.doCall(ProtobufPlugin.groovy:369)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.gradle.util.internal.ClosureBackedAction.execute(ClosureBackedAction.java:73)
at org.gradle.util.internal.ConfigureUtil.configureTarget(ConfigureUtil.java:155)
at org.gradle.util.internal.ConfigureUtil.configureSelf(ConfigureUtil.java:131)
at org.gradle.api.internal.AbstractTask.configure(AbstractTask.java:666)
at org.gradle.api.DefaultTask.configure(DefaultTask.java:309)
.
.
.
gradle version: gradle 7.5
gradle JVM version: GraalVM version 17.0.3
IDE: intellij ide 2022.1.3
Thank you for any help.
You're using a very outdated version of the Protobuf Gradle plugin. Version 0.8.10 (2019) predates Gradle 7 (2021). The issue you're facing is likely to be fixed by upgrading the plugin.
plugins {
id "com.google.protobuf" version "0.8.19"
}
I'm in the process of converting a JDK 8 app over to JDK 11. It builds using Gradle and uses JPA/Hibernate under the hood. I've upgraded the necessary Gradle modules, Spring Boot is now 2.1 and it's using the Gradle 5.1 wrapper. It uses QueryDSL JPA annotation processing to build the Q* classes off of a PostgreSQL database.
The following task in the build script generates the aformentioned classes:
compileJava {
doFirst {
generatedSourcesDir.mkdirs();
}
options.compilerArgs += [
'-s', generatedSourcesDir,
]
// dependsOn generateQueryDSL
}
And the commented-out QueryDSL generation task is:
task generateQueryDSL(type: JavaCompile, group: 'build', description: 'Generates the QueryDSL query types') {
source = sourceSets.main.java
classpath = configurations.compile + configurations.querydslapt
options.compilerArgs = [
"-proc:only",
"-processor", "com.querydsl.apt.jpa.JPAAnnotationProcessor"
]
destinationDir = generatedSourcesDir
}
The main error I'm receiving when running the Gradle compileJava task is the following:
* What went wrong:
Execution failed for task ':app-base:compileJava'.
> java.lang.NoClassDefFoundError: javax/persistence/Entity
I'm using the following build dependency:
compile group: 'org.eclipse.persistence', name: 'javax.persistence', version: '2.2.1'
Which hasn't been updated since last summer. Is there any way I can make the JavaCompile Gradle task work with JDK 11 and JPA 2.2?
UPDATE 2/1/2019 - build.gradle for the API project as requested by a user (works with JDK 11 and Spring Boot 2.1 and Gradle 4.8, it needs significant cleanup though for Gradle 5)
buildscript {
repositories {
jcenter()
mavenLocal()
mavenCentral()
maven { url "http://repo.spring.io/libs-release" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.2.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: "jacoco"
jar {
enabled = true
}
repositories {
mavenLocal()
mavenCentral()
maven { url "http://repo.spring.io/libs-release" }
}
ext {
generatedSourcesDir = file("${buildDir}/generated-sources")
pojogenGeneratedDir = file("src/pojogen")
}
sourceSets {
main {
java {
srcDir "src/main/java"
srcDir pojogenGeneratedDir
srcDir generatedSourcesDir
}
}
}
configurations {
provided
compile.extendsFrom provided
}
compileJava {
doFirst {
generatedSourcesDir.mkdirs();
}
options.compilerArgs += [
'-s', generatedSourcesDir,
]
}
jar {
enabled = true
}
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
dependencies {
/*
SPRING
*/
testCompile("org.springframework.boot:spring-boot-starter-test:2.1.2.RELEASE")
// tag::tomcat[]
compile("org.springframework.boot:spring-boot-starter-web:2.1.2.RELEASE") {
exclude module: "spring-boot-starter-jetty:2.1.2.RELEASE"
}
compile("org.springframework.boot:spring-boot-starter-tomcat:2.1.2.RELEASE")
// end::tomcat[]
// tag::actuator[]
compile("org.springframework.boot:spring-boot-starter-actuator:2.1.2.RELEASE")
compile("org.springframework.boot:spring-boot-starter-security:2.1.2.RELEASE")
compile("org.springframework.boot:spring-boot-starter-data-jpa:2.1.2.RELEASE")
compile("org.springframework.boot:spring-boot-starter-batch:2.1.2.RELEASE")
compile("org.springframework.boot:spring-boot-devtools:2.1.2.RELEASE")
// end::actuator[]
/*
APACHE COMMONS
*/
// https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.8.1'
// https://mvnrepository.com/artifact/commons-io/commons-io
compile group: 'commons-io', name: 'commons-io', version: '2.6'
/*
GOOGLE GUAVA
*/
// https://mvnrepository.com/artifact/com.google.guava/guava
compile group: 'com.google.guava', name: 'guava', version: '27.0.1-jre'
/*
LOGBACK
*/
// https://mvnrepository.com/artifact/ch.qos.logback/logback-classic
testCompile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
/*
MOCKITO
*/
// https://mvnrepository.com/artifact/org.mockito/mockito-core
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.23.4'
/*
JWT
*/
// https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt
compile group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1'
/*
MAIL
*/
// https://mvnrepository.com/artifact/com.sun.mail/javax.mail
compile group: 'com.sun.mail', name: 'javax.mail', version: '1.6.2'
// https://mvnrepository.com/artifact/javax.mail/javax.mail-api
compile group: 'javax.mail', name: 'javax.mail-api', version: '1.6.2'
/*
SWAGGER
*/
// https://mvnrepository.com/artifact/io.springfox/springfox-swagger2
compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2'
// https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2'
/*
PASSWORD VALIDATOR
*/
// https://mvnrepository.com/artifact/org.passay/passay
compile group: 'org.passay', name: 'passay', version: '1.3.1'
/*
LOMBOK
*/
// https://mvnrepository.com/artifact/org.projectlombok/lombok
provided group: 'org.projectlombok', name: 'lombok', version: '1.18.4'
/*
Thymeleaf
*/
// // https://mvnrepository.com/artifact/org.thymeleaf/thymeleaf
// compile group: 'org.thymeleaf', name: 'thymeleaf', version: '3.0.9.RELEASE'
//
// // https://mvnrepository.com/artifact/org.thymeleaf/thymeleaf-spring4
// compile group: 'org.thymeleaf', name: 'thymeleaf-spring4', version: '3.0.9.RELEASE'
/*
H2 (unit testing)
*/
// https://mvnrepository.com/artifact/com.h2database/h2
testCompile group: 'com.h2database', name: 'h2', version: '1.4.197'
/*
Thumbnail tools
*/
// https://mvnrepository.com/artifact/net.coobird/thumbnailator
compile group: 'net.coobird', name: 'thumbnailator', version: '0.4.8'
/*
JUNIT
*/
testCompile("junit:junit")
}
/*
BUILD EXCLUSIONS
*/
test {
systemProperties 'property': 'value'
testLogging {
events "passed", "skipped", "failed", "standardOut", "standardError"
}
}
/*
JaCoCo
*/
jacoco {
toolVersion = "0.7.6.201602180812"
reportsDir = file("$buildDir/customJacocoReportDir")
}
jacocoTestReport {
reports {
xml.enabled false
csv.enabled false
html.destination "${buildDir}/jacocoHtml"
}
}
I got it to work with JDK 11 by rolling back Gradle to 4.8 and rolling back Hibernate dependencies. Ask further if interested in exact dependencies I'm using.
I'm running my gradle project with "gradle bootrun" on a cmd prompt window.
The error I get is this:
What went wrong:
A problem occurred configuring root project 'kyp4-backend'.
Could not resolve all artifacts for configuration ':classpath'.
Could not find org.springframework.boot:spring-boot-gradle-plugin:1.4.0.BUILD-SNAPSHOT.
Searched in the following locations:
https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-gradle-plugin/1.4.0.BUILD-SNAPSHOT/maven-metadata.xml <-- PRODUCES 404 ERROR when you go to page
https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-gradle-plugin/1.4.0.BUILD-SNAPSHOT/spring-boot-gradle-plugin-1.4.0.BUILD-SNAPSHOT.pom <-- PRODUCES 404 ERROR when you go to page
https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-gradle-plugin/1.4.0.BUILD-SNAPSHOT/spring-boot-gradle-plugin-1.4.0.BUILD-SNAPSHOT.jar <-- PRODUCES 404 ERROR when you go to page
Required by:
project :
************ GRADLE *****************
So here's my build.gradle file:
buildscript {
ext {
springBootVersion = '1.5.3.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.0.BUILD-SNAPSHOT") ***<-- THIS DOESN'T EXIST on repo.Spring.io. Only 1.2.0 = 5.x*** or ***<-- on repo.spring.io***
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
apply plugin: 'org.springframework.boot'
//apply plugin: 'war'
version = '0.0.1'
sourceCompatibility = 1.8
repositories {
jcenter()
mavenCentral()
flatDir {
dirs 'repository'
}
mavenCentral()
}
ext {
springCloudVersion = 'Edgware.SR3'
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-aop')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-web')
compile("org.springframework.boot:spring-boot-devtools")
compile('org.springframework.boot:spring-boot-starter-actuator')
compile group: 'joda-time', name: 'joda-time'
compile group: 'com.myfolder', name: 'all_pfs', version: '7.1.9'
compile group: 'com.myfolder', name: 'pfs-client', version: '7.1.9'
compile group: 'com.myfolder.pfs.wic', name: 'pfs-wic', version: '1.1.0.RC3'
compile group: 'com.picketlink.picketlink', name: 'picketlink-fed', version: '2.0.3-SNAPSHOT'
compile group: 'commons-httpclient', name: 'commons-httpclient', version: '3.1'
compile group: 'commons-lang', name: 'commons-lang', version: '2.6'
compile group: 'org.apache.httpcomponents', name: 'httpclient'
compile group: 'xstream', name: 'xstream', version: '1.2.2'
compile group: 'javax.ejb', name: 'javax.ejb-api', version: '3.2'
compile group: 'io.springfox', name: 'springfox-swagger2', version:'2.6.1'
compile group: 'io.springfox', name: 'springfox-swagger-ui', version:'2.6.1'
compile group: 'org.apache.commons', name: 'commons-io', version: '1.3.2'
compile group: 'commons-beanutils', name: 'commons-beanutils', version: '1.8.3'
compile group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version: '1.9.13'
compile group: 'org.springframework', name: 'spring-messaging', version: '4.2.6.RELEASE'
compile group: 'org.springframework', name: 'spring-websocket', version: '4.3.11.RELEASE'
compile('org.springframework.boot:spring-boot-starter-test')
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '1.5.6.RELEASE'
testCompile group: 'com.microsoft.sqlserver', name: 'sqljdbc4', version: '4.0'
compile name: "sqljdbc4-4.0"
//Added to implement slf4j logger
compile group: 'org.slf4j', name:'slf4j-api', version: '1.7.2'
//compile group: 'ch.qos.logback', name:'logback-classic', version: '1.0.9'
//compile group: 'ch.qos.logback', name:'logback-core', version: '1.0.9'
// jsoup HTML parser library # https://jsoup.org/
compile 'org.jsoup:jsoup:1.11.3'
compile group: 'com.datastax.cassandra',name: 'cassandra-driver-core',version:'3.2.0'
compile('org.springframework.boot:spring-boot-starter-data-cassandra')
compile('org.projectlombok:lombok:1.18.2')
compile group: 'com.myfolder.service.fusion.audit.client', name: 'audit-client', version: '2.0.1.RELEASE'
compile group: 'org.apache.httpcomponents', name: 'httpasyncclient', version: '4.1.3'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
But this is all starting with org.springframework.boot/.context/web.client does not exist:
Here's a couple images to show:
I deleted the Netbeans CACHE and let Netbeans rebuild projects and indicies... still, no joy!
Any help or insight would be greatly appreciated.
You have configured your buildscript to use Maven Central as its only repository:
repositories {
mavenCentral()
}
You have also configured it to depend on 1.4.0.BUILD-SNAPSHOT of Spring Boot's Gradle Plugin:
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.0.BUILD-SNAPSHOT")
}
Snapshots are not published to Maven Central, only releases are published there. Milestones and snapshots are published to https://repo.spring.io. Specifically, snapshots are available from https://repo.spring.io/snapshot and milestones are available from https://repo.spring.io/milestone. You can find 1.4.0.BUILD-SNAPSHOT of Boot's Gradle plugin here.
If you want to use a snapshot version of Spring Boot, you should add https://repo.spring.io/snapshot and https://repo.spring.io/milestone to the configured repositories:
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/snapshot' }
maven { url 'https://repo.spring.io/milestone' }
}
The milestone repository is required as a Spring Boot snapshot may have milestone dependencies.
Alternatively, and particularly given that 1.4.0 is rather old now and no longer supported, you may want to upgrade to a more recent release. At the time of writing, 1.5.17.RELEASE is the latest in the 1.x line and 2.1.0.RELEASE is the latest in the 2.x line.
You could upgrade to 1.5.17.RELEASE like this:
buildscript {
ext {
springBootVersion = '1.5.17.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion")
}
}
I have a Parent Module Gradle project which contains sub-projects. One of those sub-projects is a web application. When I'm publishing to the maven repo, it is published as ONLY the jar file despite having both jar and war created locally
Parent file Gradle settings:
configurations {
integTestCompile.extendsFrom testCompile
integTestRuntime.extendsFrom testRuntime
}
allprojects {
ext {
springVersion = "4.0.4.RELEASE"
}
tasks.withType(JavaCompile) {
sourceCompatibility = "1.6"
targetCompatibility = "1.6"
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'
repositories {
maven {
url "http://.../mirror/"
}
}
publishing {
publications {
maven(MavenPublication) {
groupId 'com.blah'
version '1.2'
from components.java
}
}
repositories {
maven {
credentials {
username ""
password ""
}
if(project.version.endsWith('-SNAPSHOT')) {
url "http://.../snapshots/"
} else {
url "http:/.../internal/"
}
}
}
}
dependencies {
testCompile 'junit:junit:4.8.2'
}
}
And the web application gradle
apply plugin: 'war'
configurations {
providedRuntime
}
war {
baseName = 'portal-web'
}
dependencies {
compile(project(":portal-web-breadcrumb"))
compile(project(":portal-entity"))
compile(group: 'commons-beanutils', name: 'commons-beanutils', version: '20030211.134440')
compile(group: 'commons-digester', name: 'commons-digester', version: '2.1')
compile(group: 'org.apache.tiles', name: 'tiles-api', version: '3.0.1')
compile(group: 'org.apache.tiles', name: 'tiles-core', version: '3.0.1')
compile(group: 'org.apache.tiles', name: 'tiles-jsp', version: '3.0.1')
compile(group: 'org.slf4j', name: 'slf4j-api', version: '1.7.5')
compile(group: 'org.slf4j', name: 'log4j-over-slf4j', version: '1.7.5')
compile(group: 'javax.servlet', name: 'jstl', version: '1.2')
compile(group: 'taglibs', name: 'standard', version: '1.1.2')
compile(group: 'org.springframework', name: 'spring-core', version: "$springVersion")
compile(group: 'org.springframework', name: 'spring-web', version: "$springVersion")
compile(group: 'org.springframework', name: 'spring-webmvc', version: "$springVersion")
compile(group: 'log4j', name: 'log4j', version: '1.2.15') {
exclude group: 'javax.mail', module: 'mail'
exclude group: 'javax.jms', module: 'jms'
exclude group: 'com.sun.jdmk', module: 'jmxtools'
exclude group: 'com.sun.jmx', module: 'jmxri'
}
providedCompile('javax.servlet:javax.servlet-api:3.1.0')
providedCompile(group: 'javax.servlet', name: 'jsp-api', version: '2.0')
providedCompile(group: 'javax', name: 'javaee-api', version: '6.0')
}
Thanks
For publishing a War, configure the MavenPublication with from components.web.
Add this under your publishing:
publications {
mavenWeb(MavenPublication) {
from components.web
}
}
I have a war project (project A) that has a compile dependency on another project that contains shared libraries (project B), however I don't want the transitive dependencies of the project B to be included on the WTP deployment.
When I generate the war file using gradle the transitive dependencies from Project B are ignored as I want to, however WTP keeps copying all libs into the /WEB-INF/lib directory and therefore I have classloader issues.
I have tried to to ignore transitive dependencies from Project B using transitive = false and ignoring specific dependencies with exclude both at dependency and configuration level with not success so far and I can't find what I'm doing wrong.
Thanks in advance.
My configuration is as follows:
Project A
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'eclipse-wtp'
apply plugin: 'war'
repositories {
mavenLocal()
mavenCentral()
maven { // ext release
url "${artifactory_contextUrl}/ext-release-local"
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
maven { // libs release
url "${artifactory_contextUrl}/libs-release-local"
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
maven { // libs snapshot
url "${artifactory_contextUrl}/libs-snapshot-local"
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
maven { // SpringSource Enterprise Bundle Repository - SpringSource Bundle Releases
url "http://repository.springsource.com/maven/bundles/release" }
maven { // SpringSource Enterprise Bundle Repository - External Bundle Releases
url "http://repository.springsource.com/maven/bundles/external" }
maven { // SpringSource Enterprise Bundle Repository - SpringSource Library Releases
url "http://repository.springsource.com/maven/libraries/release" }
maven { // SpringSource Enterprise Bundle Repository - External Library Releases
url "http://repository.springsource.com/maven/libraries/external" }
}
group = 'com.thisproject'
sourceCompatibility = '1.6'
version = '1.6'
war {
baseName = 'ROOT'
archiveName = baseName+'.'+extension
destinationDir = file('build/')
}
task deployToFolder(dependsOn: 'war') << {
copy {
from war.archivePath
into "${deployFolder}"
}
}
task jenkinsTest{
inputs.files test.outputs.files
doLast{
def timestamp = System.currentTimeMillis()
test.testResultsDir.eachFile { it.lastModified = timestamp }
}
}
build.dependsOn(jenkinsTest)
configurations {
runtime.exclude group: 'commons-validator', module: 'commons-validator'
runtime {
transitive = false
}
}
dependencies{
providedCompile group: 'log4j', name: 'log4j', version: '1.2.16'
providedCompile group: 'org.springframework.security', name: 'org.springframework.security.web', version: '3.1.1.RELEASE'
providedCompile group: 'org.springframework.security', name: 'spring-security-config', version: '3.1.1.RELEASE'
providedCompile group: 'org.springframework.social', name: 'spring-social-web', version: '1.0.2.RELEASE'
providedCompile group: 'org.springframework.social', name: 'spring-social-core', version: '1.0.2.RELEASE'
providedCompile group: 'org.springframework.social', name: 'spring-social-facebook', version: '1.0.1.RELEASE'
providedCompile group: 'org.springframework.social', name: 'spring-social-twitter', version: '1.0.2.RELEASE'
providedCompile group: 'spring-social-google', name: 'spring-social-google', version: '1.0'
providedCompile group: 'jstl', name: 'jstl', version: '1.2'
providedCompile group: 'org.springframework.security', name:'org.springframework.security.taglibs', version:'3.1.1.RELEASE'
compile(project(':projectB')) {
exclude module:'commons-validator'
transitive = false
}
providedCompile group: 'javax.servlet', name: 'servlet-api', version: '2.5'
providedCompile group: 'javax.servlet', name: 'jsp-api', version: '2.0'
providedCompile group: 'org.springframework', name: 'org.springframework.transaction', version: '3.1.1.RELEASE'
providedCompile group: 'commons-validator', name: 'commons-validator', version: '1.2.0'
providedCompile group: 'commons-lang', name: 'commons-lang', version: '2.4'
providedCompile group: 'javax.validation', name: 'validation-api', version: '1.0.0.GA'
providedCompile 'javax.persistence:persistence-api:1.0.2'
providedCompile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.10.Final'
}
eclipse {
project { natures 'org.springsource.ide.eclipse.gradle.core.nature' }
wtp {
component { deployName = 'ROOT' }
facet {
facet name: 'jst.web', version: '2.5'
facet name: 'jst.java', version: '1.6'
}
}
}
compileJava {
options.encoding = "UTF-8"
}
Project B
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'maven'
repositories {
mavenLocal()
mavenCentral()
maven { // ext release
url "${artifactory_contextUrl}/ext-release-local"
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
maven { // libs release
url "${artifactory_contextUrl}/libs-release-local"
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
maven { // libs snapshot
url "${artifactory_contextUrl}/libs-snapshot-local"
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
maven { // SpringSource Enterprise Bundle Repository - SpringSource Bundle Releases
url "http://repository.springsource.com/maven/bundles/release"
}
maven { // SpringSource Enterprise Bundle Repository - External Bundle Releases
url "http://repository.springsource.com/maven/bundles/external"
}
maven { // SpringSource Enterprise Bundle Repository - SpringSource Library Releases
url "http://repository.springsource.com/maven/libraries/release"
}
maven { // SpringSource Enterprise Bundle Repository - External Library Releases
url "http://repository.springsource.com/maven/libraries/external"
}
}
group = 'com.thisproject'
sourceCompatibility = '1.6'
version = '1.7.26-SNAPSHOT'
jar {
manifest {
attributes 'Implementation-Title': 'Gradle Quickstart', 'Implementation-Version': version
}
destinationDir = file('build/')
}
task deployToFolder(dependsOn: 'jar') << {
copy {
from jar.archivePath
into "${deployFolder}"
}
}
task sourcesJar(type: Jar, dependsOn:classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives sourcesJar
}
dependencies{
compile group: 'log4j', name: 'log4j', version: '1.2.16'
compile group: 'commons-logging', name: 'commons-logging', version: '1.1.1'
compile group: 'com.lowagie', name: 'itext', version: '2.0.8'
compile group: 'commons-codec', name: 'commons-codec', version: '1.6'
compile group: 'commons-lang', name: 'commons-lang', version: '2.4'
compile group: 'commons-io', name: 'commons-io', version: '1.4'
compile group: 'commons-validator', name: 'commons-validator', version: '1.2.0'
compile group: 'org.apache.axis', name: 'axis-jaxrpc', version: '1.4'
compile group: 'com.esendex', name: 'esendex.sdk', version: '1.0'
compile group: 'org.apache.lucene', name: 'lucene-core', version: '1.9.1'
compile group: 'org.apache.lucene', name: 'lucene-snowball', version: '1.9.1'
compile group: 'com.sun.jersey', name: 'jersey-client', version: '1.12'
compile group: 'com.sun.jersey', name: 'jersey-json', version: '1.12'
compile group: 'com.sun.jersey.ri', name: 'jax-rs-ri', version: '1.12'
compile group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version: '1.9.2'
compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.10.Final'
compile group: 'org.hibernate', name: 'hibernate-validator', version: '4.3.1.Final'
compile group: 'org.springframework', name: 'org.springframework.aop', version: '3.1.1.RELEASE'
compile group: 'org.springframework', name: 'org.springframework.beans', version: '3.1.1.RELEASE'
compile group: 'org.springframework', name: 'org.springframework.context', version: '3.1.1.RELEASE'
compile group: 'org.springframework', name: 'org.springframework.jdbc', version: '3.1.1.RELEASE'
compile group: 'org.springframework', name: 'org.springframework.orm', version: '3.1.1.RELEASE'
compile group: 'org.springframework', name: 'org.springframework.oxm', version: '3.1.1.RELEASE'
compile group: 'org.springframework', name: 'org.springframework.transaction', version: '3.1.1.RELEASE'
compile group: 'org.springframework', name: 'org.springframework.web.servlet', version: '3.1.1.RELEASE'
compile group: 'spring-social-jpa', name: 'spring-social-jpa', version: '0.0.1'
compile group: 'javax.xml.bind', name: 'jsr173_api', version: '1.0'
compile group: 'javax.validation', name: 'validation-api', version: '1.0.0.GA'
compile group: 'com.googlecode.libphonenumber', name: 'libphonenumber', version: '4.1'
compile group: 'axis', name: 'axis', version: '1.4'
compile group: 'org.apache.commons', name: 'commons-email', version: '1.2'
compile group: 'org.apache.tomcat', name: 'catalina', version: '6.0.35'
compile group: 'javax.servlet', name: 'servlet-api', version: '2.5'
compile group: 'javax.servlet', name: 'jsp-api', version: '2.0'
compile group: 'org.springframework.security', name: 'org.springframework.security.web', version: '3.1.1.RELEASE'
compile group: 'commons-httpclient', name: 'commons-httpclient', version: '3.0.1'
compile group: 'net.sf.opencsv', name: 'opencsv', version: '2.0'
testCompile 'junit:junit:4.11'
testCompile group: 'org.springframework', name: 'org.springframework.test', version: '3.1.1.RELEASE'
testCompile 'mysql:mysql-connector-java:5.1.22'
testCompile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.10.Final'
testCompile group: 'org.hibernate', name: 'hibernate-entitymanager', version: '3.6.10.Final'
testCompile 'org.hibernate:hibernate-validator:4.3.1.Final'
compile(group: 'com.paypal.sdk', name: 'merchantsdk', version: '2.2.98')
compile(group: 'com.paypal.sdk', name: 'paypal-core', version: '1.1.1')
}
compileJava {
options.encoding = "UTF-8"
}
After a massive search through net and digging into so many Gradle and WTP stuff, I was able to get this working. Basically, there are three ways to ignore dependencies in WTP deploy directory (or I am aware of only three of them!).
1. Setting transitive to false
As you have mentioned in the question and the syntax is like:
compile('group.id:jar.name:1.0') {transitive = false}
runtime('group.id:jar.name:1.0') {transitive = false}
This should prevent the dependant JARs of being added to final WTP directory.
2. Excluding using provided syntax
Gadle comes with a feature to prevent dependencies of being added to final WAR file which in here can be used to prevent them of being copied to WTP deploy dir. And here is the syntax:
providedCompile 'group.id:jar.name:1.0'
providedRuntime 'group.id:jar.name:1.0'
3. HACK!!
Here comes the most interesting part. What if none of the above works? I found this thread on STS jira which is about same issue and that pointed me to this solution which did not work for me but gave me a clue to do my own hack as follow. In the build script I added following code to ignore the dependencies manually:
subprojects {
project.afterEvaluate {
eclipse.classpath.file.withXml {
it.asNode().'classpathentry'.each { entry ->
def path = entry.#path.toLowerCase()
if (path.contains('your-jar-to-ignore')) {
entry.attributes.each { attr ->
if (attr.attribute.#name.contains('org.eclipse.jst.component.dependency')) {
entry.remove(attr)
}
}
}
}
}
}
}
It hacks into the process of generating .classpath file (which is done by gradle) and prevents it of adding dependency attribute to the specified JAR. This way it doesn't get copied to WTP deploy directory.
Hope this helps people who land on this page, but I really think either Eclipse or Gradle people should fix this issue as it is very frustrating.