Setting up Gradle Cargo - gradle

I am trying follow this tutorial to set up Grails/ Cargo: https://github.com/bmuschko/gradle-cargo-plugin I wish to use this plugin to deploy wars to local tomcat instances and to start and stop them.
Here is my build.gradle
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'cargo'
sourceCompatibility = 1.5
version = '1.0'
jar {
manifest {
attributes 'Implementation-Title': 'Gradle Quickstart', 'Implementation-Version': version
}
}
repositories {
mavenCentral()
}
dependencies {
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
testCompile group: 'junit', name: 'junit', version: '4.+'
classpath 'org.gradle.api.plugins:gradle-cargo-plugin:0.6.1'
def cargoVersion = '1.3.3'
cargo "org.codehaus.cargo:cargo-core-uberjar:$cargoVersion",
"org.codehaus.cargo:cargo-ant:$cargoVersion"
}
cargo {
containerId = 'tomcat6x'
port = 9090
deployable {
file = file('/Users/me/Documents/gradlemucks/grails_2/hello-world/target/hello-world-0.1.war')
context = 'helloworld'
}
local {
homeDir = file('/Users/me/developer/servers/apache-tomcat-6.0.37')
output = file('build/output.log')
tomcat {
ajpPort = 9091
}
}
}
test {
systemProperties 'property': 'value'
}
uploadArchives {
repositories {
flatDir {
dirs 'repos'
}
}
}
When I do gradle tasks in the terminal I get:
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/me/Documents/workspaces/regress_test/httptests/build.gradle' line: 3
* What went wrong:
A problem occurred evaluating root project 'httptests'.
> Plugin with id 'cargo' not found.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
What are my doing wrong?

The buildscript itself need the cargo dependency so adding:
buildscript {
repositories {
mavenCentral()
}
dependencies { classpath "org.gradle.api.plugins:gradle-cargo-plugin:0.6" }
}
should make it able to find the cargo plugin.

Related

Not able to create JAR file for gradle project

I want to create a jar file which I can upload on AWS, but every time I run the command 'gradle jar' from command prompt I get the following error.
> Task :compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --
debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
I get 'Build Successful' whenever I run 'gradle clean' in command prompt. Here is the content of build.gradle:
buildscript {
ext {
springBootVersion = '2.0.4.RELEASE'
}
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath "net.ltgt.gradle:gradle-apt-plugin:0.18"
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'net.ltgt.apt'
group = 'com.myproject.api'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = JavaVersion.VERSION_1_8
ext {
lombokVersion = '1.16.20'
mapstructVersion = '1.2.0.Final'
}
repositories {
mavenCentral()
mavenLocal()
jcenter()
flatDir {
dirs 'libs'
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-mail')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
compile('org.springframework.data:spring-data-jpa')
compile('io.springfox:springfox-swagger2:2.9.2')
compile('io.springfox:springfox-swagger-ui:2.9.2')
compile group: 'commons-io', name: 'commons-io', version: '2.6'
compile group: 'org.json', name: 'json', version: '20180813'
compile files('libs/checksum_2.0.0.jar')
compileOnly("org.projectlombok:lombok:${lombokVersion}")
compileOnly("org.mapstruct:mapstruct-jdk8:${mapstructVersion}")
compileOnly("org.mapstruct:mapstruct-processor:${mapstructVersion}")
runtime('org.springframework.boot:spring-boot-devtools')
runtime('mysql:mysql-connector-java')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
eclipse {
classpath {
file.whenMerged { cp ->
cp.entries.add( new org.gradle.plugins.ide.eclipse.model.SourceFolder('build/generated/source/apt/ma
in', null) )
}
}
}
Do I need to add any plugins? Thanks in advance. Please help
Open task manger and force stop Java(TM) Platform SE binary and delete
C:\Users\{current user}\.gradle\caches\jars-9\jars-9.lock file
I was using 'gradle clean' and 'gradle build' instead of 'gradlew clean' and 'gradlew build'. gradlew commands worked for me.

Gradle: create .jar from .class files and include it in EAR_dir/lib when EAR is built

You'd think this'd be easy enough. Gradle/Maven were designed specifically to get rid of build nightmares. And yet... I have scoured the web, including SO. I would prefer to be using Maven but alas this is not in my control.
My master build.gradle file looks like this:
buildscript {
repositories {
maven { url "https://aaa.com/xxxx/aaa-mvn" }
}
dependencies {
{redacted}
classpath "com.aaa.plugin.gradle:module-plugin:1.+"
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.4.4"
}
}
apply plugin: 'maven-publish'
apply plugin: {redacted}
apply plugin: {redacted}
apply plugin: 'build-defaults'
apply plugin: 'module-plugin'
apply plugin: 'war'
description = 'xxxxxx'
defaultTasks 'build','install'
dependencies {
jbossModule(group: 'com.aaa.bbbb', name: 'inf-jdbc', version: '3.0.2')
}
artifactory {
publish {
repoKey=version.endsWith("SNAPSHOT") ? 'aaa-mvn-dist-snapshots' : 'aaa-mvn-dist'
defaults {
publications('mavenJava')
}
}
}
publishing {
publications {
mavenJava(MavenPublication) {
artifact project(':xxxEAR').ear
}
}
}
repositories {
maven { url "https://xxxx.aaa.com/artifactory/aaa-mvn" }
}
This is gradle.build for my .war. I have a .war inside an .ear.
description = 'Pricing'
buildscript {
repositories {
maven { url "https://xxx.aaa.com/artifactory/aaa-mvn" }
}
dependencies {
classpath "com.aaa.plugin.gradle:ucd-publish-plugin:1.+"
classpath "com.aaa.plugin.gradle:build-defaults-plugin:1.+"
classpath {redacted}
classpath {redacted}
}
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'jacoco'
apply plugin: {redacted}
apply plugin: 'ucd-publish'
apply plugin: 'build-defaults'
apply plugin: {redacted}
apply plugin: 'maven'
apply plugin: 'maven-publish'
repositories {
maven { url "https://xxxx.aaa.com/artifactory/aaa-mvn" }
}
war {
archiveName 'xxxx.war'
}
dependencies {
compile {redacted}
compileOnly group: 'javax', name: 'javaee-api', version:'7.0'
testCompile "junit:junit:4.12"
compile 'io.swagger:swagger-annotations:1.5.10'
compile(group: 'com.aaa.inf', name: 'inf-jdbc', version: '3.0.2', classifier: 'sources')
compile(group: 'com.aaa.inf', name: 'inf-throttle', version: '3.0.1')
compile(group: 'com.ibm.db2', name: 'db2jcc', version: '3.64.133')
compile {redacted}
}
jacocoTestCoverageVerification {
violationRules {
rule {
limit {
minimum = 0.0
}
}
}
}
The build.gradle file for my .ear is:
description = 'xxxxx'
buildscript {
repositories {
maven { url "https://xxxx.aaa.com/artifactory/aaa-mvn" }
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.4.5"
classpath "com.aaa.plugin.gradle:build-defaults-plugin:1.+"
classpath "com.aaa.plugin.gradle:ucd-publish-plugin:1.+"
classpath "com.aaa.plugin.gradle:openapi-generator-gradle-plugin:1.+"
}
}
apply plugin: 'ear'
apply plugin: 'maven'
apply from: 'build.local-jboss.gradle'
apply plugin: 'maven-publish'
apply plugin: {redacted}
apply plugin: 'ucd-publish'
apply plugin: 'build-defaults'
apply plugin: {redacted}
configurations{
gen
}
dependencies {
deploy project (path: ":pricingWAR", configuration: 'archives')
earlib 'com.aaa.inf:inf-api-auth:1.4.+'
earlib {redacted}
earlib group: 'javax.security.enterprise', name: 'javax.security.enterprise-api', version: '1.0'
earlib (group: {redacted}) {
exclude group: 'javax.security.dddddd'
}
gen "io.swagger:swagger-codegen:2.2.2"
}
artifacts{
archives ear
}
repositories {
maven {
url "https://xxxx.aaa.com/artifactory/aaa-mvn"
}
}
task cleanVolumes(type: Delete) {
delete fileTree(dir: "./volumes/deployments/")
}
task copyEar(type: Copy) {
tasks.cleanVolumes.execute()
from "build/libs"
into "${project.projectDir}/volumes/deployments"
fileMode = 0644
}
build.finalizedBy(generateSwagger)
swaggerConfig {
archive = ear.archivePath
outputFormat = "JSON"
outputPath = project.buildDir.toString() + "/swagger"
}
Just looking to do this: .jar up the .class files compiled in my business classes and add them to EAR_file\lib.
I've gone so far as to try to use Gradle's native Groovy nature to write code that builds the .jar and moves it into EAR_file\lib. This of course is ridiculous. And worse still, it does not quite work. Paired with auto-deploy there are timing issues.
Some of you no doubt are wincing.
To save me from such insanity, please let me know what you know about this. I have of course tried various permutations of:
apply plugin: 'java'
...
jar {
...
}
to no avail.
Thank you in advance.
Finally have it working after helpful input from coworkers. For others' benefit here is the whole thing it ended up as:
In build.gradle in the EAR project level:
// My project is named: xxx-svc and the .war subproject is named pricing-theAPI
dependencies {
deploy project (path: ":xxx-theAPI", configuration: 'archives') // This was here already
earlib project(path: ":xxx-theAPI", configuration: 'customJar') // This is new
}
In build.gradle in the WAR project level:
configurations {
customJar
}
task doJar(dependsOn:classes, type: Jar){
from sourceSets.main.output
include 'com/xyz/xxxxx/yyyyyy/zzzz/**' // See Note 1
}
artifacts {
customJar doJar
}
Note 1: I added this modifier b/c in my case I needed only the .class files at the given location in the .jar and in fact had to exclude all others. Note the Gradle docs have the modifier "include" misidentified. They call it "includes" but in fact it is "include".

Gradle changing module from nexus snapshot repo not updated

I have a problem with a snapshot artifact not being uploaded.
I'm using snapshot version. Atrifact is marked explicitly as changing: true and cacheChangingModulesFor is set to 0 seconds.
When i run --refresh-dependecies the artifact is redownloaded properly.
I found the problem while using gradle 2.9. But after upgrading to 2.14.1 the issue remains.
Below is my build.gradle file:
buildscript {
ext {
springBootVersion = '1.3.5.RELEASE'
}
repositories {
mavenCentral()
maven { url 'http://repo.spring.io/plugins-release' }
}
// dependencies for plugins
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
classpath 'org.springframework.build.gradle:propdeps-plugin:0.0.7'
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'
apply plugin: 'propdeps'
apply plugin: 'propdeps-maven'
apply plugin: 'propdeps-idea'
configurations.all {
// Check for updates every build
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
jar {
baseName = 'someproject'
version = '0.0.1-SNAPSHOT'
}
war {
baseName = "someproject"
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://jitpack.io" }
maven {
url 'http://nexus.example.com:8081/nexus/content/repositories/java-libs-snapshots/'
credentials {
username "someuser"
password "somepassword"
}
}
}
// enables to run with dev profile: $ gradle local bootRun
task local << {
bootRun.systemProperty 'spring.profiles.active', 'local'
}
bootRun {
jvmArgs = ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"]
}
dependencies {
compile 'mysql:mysql-connector-java'
compile 'org.springframework.boot:spring-boot-starter-web'
compile group: "pl.example", name: "name", version: "0.7.6.1-SNAPSHOT", changing: true
compile 'org.jadira.usertype:usertype.core:5.0.0.GA'
compile group: 'com.rometools', name: 'rome', version: '1.6.0'
compile group: 'org.jsoup', name: 'jsoup', version: '1.9.2'
compile 'org.hibernate:hibernate-search:5.5.3.Final'
compile 'org.projectlombok:lombok:1.16.6'
}
I think you maybe have the syntax for the changing dependency slightly wrong.
Can you try replacing:
compile group: "pl.example", name: "name", version: "0.7.6.1-SNAPSHOT", changing: true
with:
compile ("pl.example:name:0.7.6.1-SNAPSHOT"){ changing = true }
Can you also try adding a line to the resolutionStrategy for cacheDynamicVersionsFor as follows:
configurations.all {
resolutionStrategy {
cacheDynamicVersionsFor 0, "seconds"
cacheChangingModulesFor 0, "seconds"
}
}

Gradle Plugin Execution Order

I have written this gradle file
group 'com.abhi'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'org.flywaydb.flyway'
sourceCompatibility = 1.8
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.flywaydb:flyway-gradle-plugin:3.2.1'
classpath 'org.jooq:jooq-codegen:3.7.1'
classpath 'com.h2database:h2:1.4.177'
}
}
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.jooq', name: 'jooq', version: '3.7.1'
compile group: 'org.jooq', name: 'jooq-meta', version: '3.7.1'
compile group: 'org.jooq', name: 'jooq-codegen', version: '3.7.1'
runtime group: 'com.h2database', name: 'h2', version: '1.4.177'
}
flyway {
url = 'jdbc:h2:file:target/foobar'
user = 'sa'
}
def writer = new StringWriter()
def xml = new groovy.xml.MarkupBuilder(writer)
.configuration('xmlns': 'http://www.jooq.org/xsd/jooq-codegen-3.7.0.xsd') {
jdbc() {
driver('org.h2.Driver')
url('dbc:h2:file:target/foobar')
user('sa')
password('')
}
generator() {
database() {
}
generate() {
}
target() {
packageName('com.abhi.jooq.models')
directory('src/main/java')
}
}
}
// Run the code generator
// ----------------------
org.jooq.util.GenerationTool.generate(
javax.xml.bind.JAXB.unmarshal(new StringReader(writer.toString()), org.jooq.util.jaxb.Configuration.class)
)
when I say gradle compile it throws an exception
Could not load schemata
java.lang.NullPointerException
at org.jooq.impl.MetaImpl.meta(MetaImpl.java:120)
at org.jooq.impl.MetaImpl.getCatalogs(MetaImpl.java:143)
at org.jooq.impl.MetaImpl.getSchemas(MetaImpl.java:168)
at org.jooq.util.jdbc.JDBCDatabase.getSchemasFromMeta(JDBCDatabase.java:135)
at org.jooq.util.jdbc.JDBCDatabase.getSchemata0(JDBCDatabase.java:124)
at org.jooq.util.AbstractDatabase.getSchemata(AbstractDatabase.java:279)
I think the problem is that the code at the bottom of the script executes much before the "flyway" plugin.
Is there a way I can ensure that the code below is executed only after the flyway plugin has executed?
Yes, if you suppose, the problem is in execution order, then you can modify it, just like with any other tasks. Take a look at the documentation of the flyway plugin. According to it, this plugin adds some extra tasks to your build script, for thos one tasks are: flywayMigrate, flywayClean etc. You can make any of your tasks depending (with dependsOn option) on the tasks form this plugin and make them running just after the plugin's job is done.

Gradle build for Java project is failing

Below build.gradle file for java project is failing
apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = 1.5
version = '1.0'
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '2.+'
testCompile "log4j:log4j:1.2.9"
testCompile 'org.testng:testng:6.8'
}
test {
// enable TestNG support
task testNGTests(type: Test) {
useTestNG() {
suites 'src/test/resources/testng.xml'
useDefaultListeners = true
}
}
}
Error:
Couldnot find property 'projectDir' on org.gradle.api.tasks.testing.testng.TestNGOptions_Decorated#1595f1bb.
Then I tried in using setting.gradle file with below code:
rootProject.name = 'AutoTest_Gradle'
project(':AutoTest_Gradle').projectDir = 'C:/workspace/AutoTest_Gradle'
Here AutoTest_Gradle is the project name.Then it is failed with below error:
Where:
Settings file 'C:\workspace\AutoTest_Gradle\settings.gradle
What went wrong:`enter code here
A problem occurred evaluating settings 'AutoTest_Gradle'.
Project with path ':AutoTest_Gradle' could not be found.
Can anyone help on this?

Resources