Liquibase plugin for gradle - java

I've been looking for a liquibase gradle plugin and found gradle-liquibase-plugin from tlberglund.
Gradle version 1.2
build file:
apply plugin: 'java'
apply plugin: 'liquibase'
repositories {
mavenCentral()
}
dependencies {
compile('org.hsqldb:hsqldb:2.2.8')
compile('org.hsqldb:sqltool:2.2.8')
compile('com.h2database:h2:1.3.167')
compile('org.liquibase:liquibase-core:2.0.1')
compile('com.augusttechgroup:groovy-liquibase-dsl:0.7.3')
compile('postgresql:postgresql:9.1-901.jdbc4')
}
buildscript {
dependencies {
classpath 'com.augusttechgroup:gradle-liquibase-plugin:0.6.1'
}
}
databases {
postgre {
url = "${postgreBaseUrl}" + "${postgreDB}"
username = "${postgreUserName}"
password = "${postgreUserPassword}"
}
}
changelogs {
main {
file = file('src/main/liquibase/mainChanges.groovy')
}
}
task dbInit << {
databases.postgre.url = "${postgreBaseUrl}"
databases.postgre.username = "${postgreRootUserName}"
databases.postgre.password = "${postgreRootUserPassword}"
changelogs.main.file = file('src/main/liquibase/tablespaceChanges.groovy')
}
Runnin gradle build fails with the following error:
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all dependencies for configuration ':classpath'.
> Could not find group:com.augusttechgroup, module:gradle-liquibase-plugin, vers
ion:0.6.1.
Required by:
:demo:unspecified
* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to
get more log output.
BUILD FAILED
Does anyone have experience with this plugin, I would really appreciate a working example.

The problem isn't related to the Liquibase plugin. You just need to declare a repository in the buildscript {} section. buildscript {} is completely separate from the rest of the script. You can almost think about it as a separate file.

Looking at the source on github (see the build.gradle file) it looks like the builds are posted on oss.sonatype.org. Try using adding "https://oss.sonatype.org/content/repositories/releases/" as a maven repository
So, your build.gradle may look like this:
buildscript {
repositories {
maven {
url uri('https://oss.sonatype.org/content/repositories/releases/')
}
mavenCentral()
}
dependencies {
classpath group:'net.saliman', name: 'gradle-liquibase-plugin', version: '1.0.0'
}
}
apply plugin: 'liquibase'

Related

Gluon Project - Springboot Dependencies not found when i run /.gradle run

Here is my issue :
When i run my mainClass as java application everything goes good :
but when i run ./gradle run springboot dependencies not found in the classPath :
the build.gradle : GitHub Repository link to file
Can anyone try to fix with me the issue i ll be more than glad !!!
I managed to resolve the issue by adding this in the build.gradle :
buildscript {
repositories {
google()
jcenter()
maven {
url 'https://nexus.gluonhq.com/nexus/content/repositories/releases'
}
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:2.0.30'
classpath "org.springframework.boot:spring-boot-gradle-plugin:2.3.3.RELEASE"
}
}
apply plugin: 'application'
dependencies {
compile "org.springframework.cloud:spring-cloud-starter-feign:1.4.7.RELEASE"
}
And now when i run /.gradle run -> it shows

Gradle ignores internal nexus repository

I have very simple java project, and I'm using gradle to build it.
And I have Linux RedHat server (without access to internet) but this server has access to internal nexus repository where all required dependencies present.
This is build.gradle file:
buildscript {
ext {
springBootVersion = '2.0.3.RELEASE'
}
repositories {
maven { url "https://nexus.com.mysite/nexus/content/repositories/mirror/" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
plugins {
id 'com.github.jacobono.jaxb' version '1.3.5' // this is 14 line
}
repositories {
maven { url "https://nexus.com.mysite/nexus/content/repositories/mirror/" }
}
subprojects {
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'maven'
apply plugin: 'io.spring.dependency-management'
sourceCompatibility = 1.8
dependencyManagement {
imports {
mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootVersion}"
}
}
buildscript {
repositories {
maven { url "https://nexus.com.mysite/nexus/content/repositories/mirror/" }
}
}
repositories {
maven { url "https://nexus.com.mysite/nexus/content/repositories/mirror/" }
}
}
allprojects {
buildscript {
repositories {
maven { url "https://nexus.com.mysite/nexus/content/repositories/mirror/" }
}
}
}
Settings file settings.gradle:
include 'api'
project(":api").name = "api"
And this project has 1 submodule api filder.
api build.gradle file:
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.github.jacobono.jaxb'
springBoot {
buildInfo()
}
group = 'com.example'
version = '1.0.0'
sourceCompatibility = 1.8
repositories {
maven { url "https://nexus.com.mysite/nexus/content/repositories/mirror/" }
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
}
springBoot {
mainClassName = 'com.example.TestApplication'
}
On my linux server I have:
- java 8
- gradle 4.5.1
- mvn 3.5.6
When I'm running gradle clean inside root folder of my project, after 5-10 mins I'm receiving error:
FAILURE: Build failed with an exception.
* Where:
Build file '/my-proj/build.gradle' line: 14
* What went wrong:
Plugin [id: 'com.github.jacobono.jaxb', version: '1.3.5'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'com.github.jacobono.jaxb:com.github.jacobono.jaxb.gradle.plugin:1.3.5')
Searched in the following repositories:
Gradle Central Plugin Repository
* 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
BUILD FAILED in 10m 3s
And for some reason in this error there is no information about my nexus repository...I assuming that it even haven't tried this repository. And the question is why...?
I would be very happy of any help...maybe I made mistake in build.gradle file somewhere...
p.s. on my local pc(I have access to internet and to this repository everything works file)
Plugins by default resolved from Gradle Plugin Portal. If you want to resolve them from different sources, You should add configuration to settings.gradle file.
Example:
pluginManagement {
repositories {
maven {
url '../maven-repo'
}
gradlePluginPortal()
ivy {
url '../ivy-repo'
}
}
}
Check the docs for details.

How to pass trustStore property in gradle build script

I am trying to generate classes for a SOAP webservice through a gradle script. I am using a plugin gradle-jaxws-plugin which is available in maven central.
My script looks like below:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "eu.schnuckelig.gradle:gradle-jaxws-plugin:1.0.2"
}
}
apply plugin: 'maven'
apply plugin: 'jaxws'
jaxws {
System.setProperty('javax.xml.accessExternalSchema', 'all')
packageName = 'com.myservice'
wsdlURL = 'https://example.org/services/users.svc?wsdl'
}
repositories {
mavenCentral()
}
If I use this script as it is, I get following error
[ant:wsimport] [ERROR] sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
One way of resolving this error, I tried is gradle build -Djavax.net.ssl.trustStore=cacerts -Djavax.net.ssl.trustStorePassword=changeit. This worked. But I want to pass these jvm properties in build script.
I tried systemProperty.set(), but it didn't work. I am trying with gradle.properties, but that doesn't work either. Is there a clean way to pass these properties? Also I am wondering how I will handle this in production when I will have an automated build.
Typically, since such data are sensitive they should be passed via command line or - if you have an automated build in production - should be configured in system via e.g. environment variables (this is how it's handled most often).
You can configure system properties via gradle.properties but they should be prepend with systemProp prefix, so:
gradle.properties:
systemProp.javax.net.ssl.trustStore=cacerts
systemProp.javax.net.ssl.trustStorePassword=changeit
Also the following piece of code put in build.gradle just under apply section should work as well:
build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "eu.schnuckelig.gradle:gradle-jaxws-plugin:1.0.2"
}
}
apply plugin: 'maven'
apply plugin: 'jaxws'
System.setProperty('javax.net.ssl.trustStore', 'cacerts')
System.setProperty('javax.net.ssl.trustStorePassword', 'changeit')
This should work
configurations {
jaxws
}
dependencies {
jaxws 'com.sun.xml.ws:jaxws-tools:2.1.4'
}
task wsimport {
ext.destDir = file("${projectDir}/src/main/generated")
System.setProperty('javax.net.ssl.keyStoreType', 'pkcs12')
System.setProperty('javax.net.ssl.keyStore', 'client.pfx')
System.setProperty('javax.net.ssl.keyStorePassword', 'xxxxxxxxx')
System.setProperty('javax.net.ssl.keyPassword', 'xxxxxxxxx')
System.setProperty('javax.net.ssl.trustStore', 'truststore.jks')
System.setProperty('javax.net.ssl.trustStorePassword', 'xxxxxxxx')
System.setProperty('sun.security.ssl.allowUnsafeRenegotiation','true')
doLast {
ant {
sourceSets.main.output.classesDir.mkdirs()
destDir.mkdirs()
taskdef(name: 'wsimport',
classname: 'com.sun.tools.ws.ant.WsImport',
classpath: configurations.jaxws.asPath
)
wsimport(keep: true,
destdir: sourceSets.main.output.classesDir,
sourcedestdir: destDir,
extension: "true",
verbose: "false",
quiet: "false",
package: "com.example.client.api",
xnocompile: "true",
wsdl: 'https://test.com/test.asmx?wsdl') {
xjcarg(value: "-XautoNameResolution")
}
}
}
}
compileJava {
dependsOn wsimport
source wsimport.destDir
}

Gradle build failed to resolve library

I am working on android (Java) and trying to consume websockets so I thought I would use this tutorial and they are using dependency org.java-websocket:Java-WebSocket:1.3.0 from this repo which has now become 1.3.1.
So I have in my modular build.gradle
dependencies {
...
compile 'org.java-websocket:Java-WebSocket:1.3.1'
...
}
and in my project / top level build.gradle I have
repositories {
jcenter()
maven { url 'http://clojars.org/repo' }
}
and I am getting error
Error:(49, 13) Failed to resolve: org.java-websocket:Java-WebSocket:1.3.1
Try it with lowercase:
compile 'org.java-websocket:java-websocket:1.3.1'
It worked for me.
Edit:
the project level gradle file:
buildscript {
repositories {
jcenter()
maven { url 'http://clojars.org/repo' }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
}
}
allprojects {
repositories {
jcenter()
maven { url 'http://clojars.org/repo' }
}
}
I was also facing same issue ,I restarted Android Studio and sync again,it build successfully.

How to compile project with Google Checkstyle rules with gradle?

I am trying to use Google checkstyle configuration (https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml) but I am constantly getting an error on gradle check:
Unable to create a Checker: cannot initialize module TreeWalker - Unable to instantiate EmptyCatchBlock
I used Gradle to build the project. Below is my gradle.build.
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'checkstyle'
sourceCompatibility = 1.8
version = '1.0'
checkstyle {
toolVersion = "6.3"
}
task "create-dirs" << {
sourceSets*.java.srcDirs*.each { it.mkdirs() }
sourceSets*.resources.srcDirs*.each { it.mkdirs() }
}
jar {
manifest {
attributes 'Implementation-Title': 'xyz',
'Implementation-Version': 0.01
}
}
repositories {
mavenCentral()
}
dependencies {
compile (
['org.apache.logging.log4j:log4j-api:2.2'],
['org.apache.logging.log4j:log4j-core:2.2']
)
testCompile(
['junit:junit:4.11'],
['org.mockito:mockito-core:1.+']
)
}
test {
systemProperties 'property': 'value'
}
uploadArchives {
repositories {
flatDir {
dirs 'repos'
}
}
}
Also, when I try to add XML config file to Checkstyle plugin in IDEA I get similar error but with a stack trace:
org.infernus.idea.checkstyle.exception.CheckStylePluginException: <html><b>The CheckStyle rules file could not be loaded.</b><br>cannot initialize module TreeWalker - Unable to instantiate EmptyCatchBlock</html>
at org.infernus.idea.checkstyle.checker.CheckerFactory.blacklistAndShowMessage(CheckerFactory.java:234)
at org.infernus.idea.checkstyle.checker.CheckerFactory.createChecker(CheckerFactory.java:188)
at org.infernus.idea.checkstyle.checker.CheckerFactory.getOrCreateCachedChecker(CheckerFactory.java:98)
at org.infernus.idea.checkstyle.checker.CheckerFactory.getChecker(CheckerFactory.java:73)
at org.infernus.idea.checkstyle.checker.CheckerFactory.getChecker(CheckerFactory.java:41)
I cannot figure out what am I doing wrong. Any help would be appreciated.
Gradle version: 2.2
You can add this configuration into your build.gradle file:
configurations {
checkstyleOverride
}
dependencies {
checkstyleOverride('com.puppycrawl.tools:checkstyle:6.11.2')
}
tasks.withType(Checkstyle) {
checkstyleClasspath = project.configurations.checkstyleOverride
}
Enjoy!
The problem lies in the fact that com.puppycrawl.tools.checkstyle.checks.blocks.EmptyCatchBlockCheck was indeed added to checkstyle but for version 6.4-SNAPSHOT. As it can be seen in checkstyle repository (pom.xml history) version 6.4-SNAPSHOT was introduced on the 02.02.2015 and EmptyCatchBlockCheck class was created on 18.02.2015.
Gradle still uses version 6.3 as in the following log extract:
:checkstyleMain
Download https://repo1.maven.org/maven2/com/puppycrawl/tools/checkstyle/6.3/checkstyle-6.3.pom
So there's simply no class You'd like to use.
According to the docs checkstyle classpath can be specified with checkstyleClasspath property - you can try to set it up manually.
I've also prepared a demo with 6.4-SNAPSHOT version, it can be found here. Checkstyle jar was built with mvn clean package with source taken from this repo.
Here is an approach that works with the (currently) latest versions of Gradle & Checkstyle (Gradle 6.1.1 & Checkstyle 8.29):
plugins {
id 'java'
id 'checkstyle'
}
configurations {
checkstyleConfig
}
dependencies {
checkstyleConfig("com.puppycrawl.tools:checkstyle:8.29") { transitive = false }
}
checkstyle {
toolVersion '8.29'
config = resources.text.fromArchiveEntry(configurations.checkstyleConfig, 'google_checks.xml')
}
Note that the Checkstyle dependency excludes transitive dependencies, otherwise the resources.text.fromArchiveEntry will fail since multiple JAR files will be present, and it will be unable to select a single one.

Categories

Resources