Not able to integrate testng with gradle. Error while building jar - gradle

I am new to gradle. Trying to integrate the testNG with Gradle and want to create jar file using "gradle build" command
This is how my build.gradle looks like
apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = 1.5
version = '1.0'
jar {
manifest {
attributes 'Implementation-Title': 'Gradle Quickstart',
'Implementation-Version': version,
'Main-Class': 'org.testng.TestNG'
}
}
repositories {
mavenCentral()
}
dependencies {
testCompile 'org.testng:testng:6.9.10'
}
test {
useTestNG(){
include '**/*'
}
}
uploadArchives {
repositories {
flatDir {
dirs 'repos'
}
}
}
However when I run the "gradle build" command I am getting following error for each testNG annotation
: error: cannot find symbol
#Test
^
Symbol: class Test
Location: class helloWorld

Related

Gradle plugin that loads org.springframework.boot into projects

I'm writing a custom gradle plugin Foo and I want to load the org.springframework.boot plugin
into projects that apply the Foo plugin. I can load various other plugins this way, but this
particular plugin doesn't want to behave the same way.
Foo build.gradle
buildscript {
ext {
springBootVersion = "2.1.3.RELEASE"
}
}
apply plugin: "groovy"
repositories {
maven { url "http://custom.repo/blah" }
}
dependencies {
implementation gradleApi()
implementation localGroovy()
implementation("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
Foo plugin
class BuildPlugin implements Plugin<Project> {
#Override
void apply(Project project) {
project.repositories {
maven { url "http://custom.repo/blah" }
}
project.plugins.apply("org.springframework.boot")
}
}
Project build.gradle
buildscript {
dependencies {
classpath files("/some/cool/path/foo-plugin.jar")
}
}
apply plugin: "com.whatever.foo-id"
Project build output
$ ./gradlew --stacktrace clean build
FAILURE: Build failed with an exception.
* Where:
Build file '/cool/project/location/bar/build.gradle' line: 40
* What went wrong:
A problem occurred evaluating root project 'bar'.
> Failed to apply plugin [id 'com.whatever.foo-id']
> Plugin with id 'org.springframework.boot' not found.
Is it possible to apply a plugin 1 from plugin 2 where plugin 1 is a classpath dependency?
This isn't possible. The classpath is what pulls in the plugins, so it is impossible for them to modify the thing before they are pulled in.

unable to run the springboot jar from command line

My requirement is to build a spring boot jar in standalone tomcat executable.I am not able to run the jar from command line.
I am using gradle
buildscript {
ext {
springBootVersion = '1.4.0.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
group = 'com.test'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile project(':testProject')
implementation('org.springframework.boot:spring-boot-starter-web')
testImplementation('org.springframework.boot:spring-boot-starter-test')
}
configurations {
all*.exclude module: 'spring-boot-starter-logging'
}
jar {
manifest {
attributes 'Implementation-Title': 'SpringAppApplication',
'Implementation-Version': version
}
}
running java -jar target/SpringAppApplication-0.0.1-SNAPSHOT.jar
I get error Invalid or corrupt jarfile SpringApp-0.0.1-SNAPSHOT.jar
.Tried giving the complete path also.

Execution of gradle bootRun fails

I'm trying to run my springboot app... It all started when i added the eureka spring-cloud plugin to my gradle.build file:
compile 'org.springframework.cloud:spring-cloud-starter-eureka'
And when i run "gradle bootRun", i get this error:
Caused by: java.io.IOException: Cannot run program "C:\Program Files\Java\jdk1.8.0_91\bin\java.exe". CreateProcess error=206, File name too long.
My build.gradle is:
import java.text.SimpleDateFormat
buildscript {
ext {
springBootVersion = '1.3.2.RELEASE'
elasticSearchVersion = '2.2.0'
groovyVersion = '2.4.5'
}
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath 'io.spring.gradle:dependency-management-plugin:0.5.5.RELEASE'
classpath 'com.github.ben-manes:gradle-versions-plugin:0.12.0'
classpath 'org.kordamp.gradle:stats-gradle-plugin:0.1.5'
}
}
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'eclipse-wtp'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.github.ben-manes.versions'
apply plugin: 'org.kordamp.gradle.stats'
def buildDate = new SimpleDateFormat('yyyyMMdd-hhmmss').format(new Date())
version = '1.0.RC1.' + buildDate
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
jcenter()
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
ext['elasticsearch.version'] = elasticSearchVersion
ext['groovy.version'] = groovyVersion
ext['guava.version'] = '18.0'
ext['lombok.version'] = '1.16.6'
dependencyManagement {
imports {
mavenBom "org.springframework.boot:spring-boot-starter-parent:${springBootVersion}"
mavenBom "org.springframework.cloud:spring-cloud-starter-parent:Brixton.M5"
mavenBom 'io.spring.platform:platform-bom:2.0.2.RELEASE'
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-aop')
compile('org.springframework.boot:spring-boot-starter-cache')
compile('org.springframework.cloud:spring-cloud-starter-hystrix')
compile 'org.jadira.usertype:usertype.extended:5.0.0.GA'
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-data-rest')
//compile('org.springframework.data:spring-data-rest-hal-browser')
compile('org.springframework.boot:spring-boot-devtools')
compile('org.springframework.boot:spring-boot-starter-hateoas')
compile('org.projectlombok:lombok')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
compile('org.springframework.boot:spring-boot-starter-web')
compile "org.elasticsearch:elasticsearch:${elasticSearchVersion}"
compile 'commons-lang:commons-lang'
compile 'commons-codec:commons-codec'
compile 'commons-collections:commons-collections'
compile 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'
compile 'org.springframework.boot:spring-boot-starter-freemarker'
compile 'de.codecentric:spring-boot-admin-starter-client:1.3.2'
compile 'org.flywaydb:flyway-core'
compile('com.domingosuarez:oneltico:0.1.2')
compile("org.springframework:spring-jms")
compile("org.apache.activemq:activemq-broker")
compile 'org.apache.activemq:activemq-pool'
compile 'org.springframework.cloud:spring-cloud-starter-eureka'
compile 'com.mashape.unirest:unirest-java:1.4.9'
runtime "org.postgresql:postgresql:9.4-1203-jdbc42"
testCompile('org.springframework.boot:spring-boot-starter-test')
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
}
}
springBoot {
executable = true
}
I take the plugin out and it executes correctly.
I know it should be a Windows problem long paths, but how can i give a solution?
tim_yates was right, thanks!
i grab the code from the link and paste it into the end of my build.gradle file, it worked like a gem!
The code i added is:
task pathingJar(type: Jar) {
dependsOn configurations.runtime
appendix = 'pathing'
doFirst {
manifest {
attributes "Class-Path": configurations.runtime.files.collect {
it.toURL().toString().replaceFirst('/file:/+/', '/')
}.join(' ')
}
}
}
bootRun {
dependsOn pathingJar
doFirst {
classpath = files("$buildDir/classes/main", "$buildDir/resources/main", pathingJar.archivePath)
}
}
Note: i added some simple quotes (') from the linkcode to get it worked though..

Spring Boot Gradle add Native library failed (java.lang.UnsatisfiedLinkError)

I am trying to add a native library( .dll file) to a basic spring gradle project.
I have tried many different settings and all of them didn't work in a basic java project , I have successfully ran that dll file by adding VM argument: java.library.path gradle
here's the script:
buildscript {
ext {
springBootVersion = '1.2.5.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'messaging'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-aop")
compile("org.springframework.boot:spring-boot-starter-amqp")
compile("org.springframework:spring-messaging")
compile('javax.inject:javax.inject:1')
compile('com.google.guava:guava:11.0.2')
compile('org.codehaus.jackson:jackson-core-asl:1.1.0')
compile('org.codehaus.jackson:jackson-mapper-asl:1.9.13')
testCompile("org.springframework.boot:spring-boot-starter-test")
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
I have tried:
add VM arguments on eclipse
add jvm properties
add gradle system property ( can not succeeded to add that parameter)
I couldn't understand why but when I follow the steps below, it worked:
1. I changed the java package name
2. rebuild the project with gradle
3. run the project

build.gradle - error deploying artifact

I'm having issues with publishing to local nexus maven repository.
I admit, I don't have much experience with using gradle.
I will say that I have tried understanding the documentation and examples that are given through the gradle website (along with a few stackoverflow questions).
I am getting the following error when I try to publish:
Execution failed for task ':publishMavenPublicationToMavenRepository'.
> Failed to publish publication 'maven' to repository 'maven'
> Error deploying artifact 'com.myproject:myproject-sdk:jar': Error deploying artifact: Resource to deploy not found: File: http://git.site.com:8081/nexus/content/repositories/releases/com/myproject/myproject-sdk/3.0.0/myproject-sdk-3.0.0.jar does not exist
the entire build.gradle file looks like this:
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'build-version'
buildscript {
repositories {
maven { url "http://git.site.com:8081/nexus/content/groups/public" }
maven { url 'https://geonet.artifactoryonline.com/geonet/public-releases' }
mavenCentral()
}
dependencies {
classpath 'nz.org.geonet:gradle-build-version-plugin:1.+'
}
}
repositories {
maven {
url "http://git.site.com:8081/nexus/content/groups/public"
}
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
compile 'com.google.code.gson:gson:2.2.4'
compile 'commons-codec:commons-codec:1.9'
}
task sourceJar(type: Jar) {
from sourceSets.main.allJava
}
publishing {
publications {
maven(MavenPublication) {
artifactId = 'myproject-sdk'
groupId = 'com.myproject'
version '3.0.0'
from components.java
artifact sourceJar {
classifier "sources"
}
}
}
repositories {
maven {
// nexus maven credentials
credentials {
username "MY_USERNAME"
password ""MY_PASSWORD"
}
if(version.endsWith('-SNAPSHOT')) {
url "http://git.site.com:8081/nexus/content/repositories/snapshots"
} else {
url "http://git.site.com:8081/nexus/content/repositories/releases"
}
}
}
}
I am using Android Studio and this project is a Java project.
I don't understand the message because it says "Resource to deploy not found" and it points to a url at nexus.
I would expect a message like "Resource to deploy not found: File: c:/directory_that_doesn't_exist/whatever.jar"
Additional Information -
The gradle tasks listed under 'All tasks' are:
assemble
build
buildDependents
buildNeeded
check
classes
clean
compileJava
compileTestJava
generatePomFileForMavenPublication
jar
javadoc
processResources
processTestResources
publish
publishMavenPublicationToMavenLocal
publishMavenPublicationToMavenRepository
publishToMavenLocal
sourceJar
test
testClasses

Resources