Gradle, how to share a catalog via a settings plugin - gradle

Experiment with the new catalog feature from Gradle 7, I'm trying to share a catalog via a settings plugin
Unfortunately documentation is quite short on that:
One option to share a catalog is to write a settings plugin, publish it on the Gradle plugin portal or an internal repository, and let the consumers apply the plugin on their settings file.
I initialized via gradle init for plugin developer using kotlin both as language and build script.
Then I swapped Project for Settings and added a dummy alias on producer
class UpgradedOctoGuacamolePlugin : Plugin<Settings> {
override fun apply(settings: Settings) {
settings.dependencyResolutionManagement {
it.versionCatalogs {
it.create("libs") {
it.alias("groovy-core").to("org.codehaus.groovy:groovy:3.0.5")
}
}
}
}
}
On consumer side settings.gradle.kts
dependencyResolutionManagement {
repositories {
mavenLocal()
mavenCentral()
maven("https://jitpack.io")
}
versionCatalogs {
create("libs") {
from("com.github.elect86:upgraded-octo-guacamole:9f454a68")
}
}
}
But at the sync
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all artifacts for configuration 'incomingPlatformsForLibs'.
> Could not resolve com.github.elect86:upgraded-octo-guacamole:9f454a68.
Required by:
unspecified:unspecified:unspecified
> No matching variant of com.github.elect86:upgraded-octo-guacamole:9f454a68 was found. The consumer was configured to find attribute 'org.gradle.internal.dm.model.builder.id' with value '0', attribute 'org.gradle.category' with value 'platform', attribute 'org.gradle.usage' with value 'version-catalog' but:
- Variant 'apiElements' capability com.github.elect86:upgraded-octo-guacamole:9f454a68:
- Incompatible because this component declares attribute 'org.gradle.category' with value 'library', attribute 'org.gradle.usage' with value 'java-api' and the consumer needed attribute 'org.gradle.category' with value 'platform', attribute 'org.gradle.usage' with value 'version-catalog'
- Other compatible attribute:
- Doesn't say anything about org.gradle.internal.dm.model.builder.id (required '0')
- Variant 'runtimeElements' capability com.github.elect86:upgraded-octo-guacamole:9f454a68:
- Incompatible because this component declares attribute 'org.gradle.category' with value 'library', attribute 'org.gradle.usage' with value 'java-runtime' and the consumer needed attribute 'org.gradle.category' with value 'platform', attribute 'org.gradle.usage' with value 'version-catalog'
- Other compatible attribute:
- Doesn't say anything about org.gradle.internal.dm.model.builder.id (required '0')
* 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 46ms
category and usage mismatch, "platform" and "version-catalog" required, but only "library" and "java-api" were found
These are my producer variants
19:15:03: Executing task 'outgoingVariants'...
Type-safe dependency accessors is an incubating feature.
> Task :outgoingVariants
--------------------------------------------------
Variant apiElements
--------------------------------------------------
Description = API elements for main.
Capabilities
- com.github.elect86:upgraded-octo-guacamole:0.0.6 (default capability)
Attributes
- org.gradle.category = library
- org.gradle.dependency.bundling = external
- org.gradle.jvm.version = 11
- org.gradle.libraryelements = jar
- org.gradle.usage = java-api
- org.jetbrains.kotlin.localToProject = public
- org.jetbrains.kotlin.platform.type = jvm
Artifacts
- build/libs/upgraded-octo-guacamole-0.0.6.jar (artifactType = jar)
Secondary variants (*)
- Variant : classes
- Attributes
- org.gradle.category = library
- org.gradle.dependency.bundling = external
- org.gradle.jvm.version = 11
- org.gradle.libraryelements = classes
- org.gradle.usage = java-api
- org.jetbrains.kotlin.localToProject = public
- org.jetbrains.kotlin.platform.type = jvm
- Artifacts
- build/classes/java/main (artifactType = java-classes-directory)
- build/classes/kotlin/main (artifactType = java-classes-directory)
- build/classes/kotlin/main (artifactType = java-classes-directory)
--------------------------------------------------
Variant runtimeElements
--------------------------------------------------
Description = Elements of runtime for main.
Capabilities
- com.github.elect86:upgraded-octo-guacamole:0.0.6 (default capability)
Attributes
- org.gradle.category = library
- org.gradle.dependency.bundling = external
- org.gradle.jvm.version = 11
- org.gradle.libraryelements = jar
- org.gradle.usage = java-runtime
- org.jetbrains.kotlin.localToProject = public
- org.jetbrains.kotlin.platform.type = jvm
Artifacts
- build/libs/upgraded-octo-guacamole-0.0.6.jar (artifactType = jar)
Secondary variants (*)
- Variant : classes
- Attributes
- org.gradle.category = library
- org.gradle.dependency.bundling = external
- org.gradle.jvm.version = 11
- org.gradle.libraryelements = classes
- org.gradle.usage = java-runtime
- org.jetbrains.kotlin.localToProject = public
- org.jetbrains.kotlin.platform.type = jvm
- Artifacts
- build/classes/java/main (artifactType = java-classes-directory)
- build/classes/kotlin/main (artifactType = java-classes-directory)
- Variant : resources
- Attributes
- org.gradle.category = library
- org.gradle.dependency.bundling = external
- org.gradle.jvm.version = 11
- org.gradle.libraryelements = resources
- org.gradle.usage = java-runtime
- org.jetbrains.kotlin.localToProject = public
- org.jetbrains.kotlin.platform.type = jvm
- Artifacts
- build/resources/main (artifactType = java-resources-directory)
(*) Secondary variants are variants created via the Configuration#getOutgoing(): ConfigurationPublications API which also participate in selection, in addition to the configuration itself.
BUILD SUCCESSFUL in 45ms
1 actionable task: 1 executed
19:15:04: Task execution finished 'outgoingVariants'.
What am I doing wrong?
I don't think I have to modify those attributes myself..
Specs:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-milestone-1-all.zip

It turned out I simply had to literally apply the plugin in the settings.gradle.kts, I didn't know you could do that
apply {
id("guacamole")
}

Related

Changing data in OpenApi info block

I'm trying to change my OpenApi info block properties.
More specifically I'm trying to change the value of the version tag in my OpenApi programmatically.
For example every new build I want a new version number.
I have tried using placeholders and giving them values in the build.gradle but haven't got it working.
openapi:
openapi: 3.1.0
info:
title: Dummy Bookshop
summary: A fictitious API demonstrating the OpenAPI Specification's features
version: ${apiVersion}
description: A fictius description.
termsOfService: https://www.dummy-book.shop/tos
contact:
name: Bookshop Support team
url: https://www.dummy-book.shop/support
email: support#dummy-book.shop
license:
name: Apache 2.0
identifier: Apache-2.0
paths: {}
build.gradle:
ext {
apiVersion = '1.0.1'
}
Does anyone have any ideas on how to get this working or is there a plugin that does this?
Create a script in your build.gradle to replace the version with the gradle version. This is easily done using the groovy YamlSlurper.
task updateYaml() {
def fileDir = "$projectDir/src/main/resources/static/"
def fileName = "myOpenApi.yml"
def reader = new FileReader(fileDir + fileName)
def slurper = new YamlSlurper()
def builder = new YamlBuilder()
builder slurper.parse(reader)
builder.content.info.version = project.version
doLast {
File newOASFile = new File(fileDir, "finalSpec.yml")
newOASFile.write(builder.toString())
}
}
Once you have the task working, set your dependencies properly. This assumes that your generation task is called generateMyOpenApi
generateMyOpenApi.dependsOn updateYaml
processResources.dependsOn generateMyOpenApi

Could not resolve all dependencies for configuration [custom configuration]

Please, I'm working on converting a gradle 2.1 project to 6.0, but I get this error.
Could not resolve all dependencies for configuration ':driver'.
> Cannot convert the provided notation to a File or URI: classesDirs.
The following types/formats are supported:
- A String or CharSequence path, for example 'src/main/java' or '/usr/include'.
- A String or CharSequence URI, for example 'file:/usr/include'.
- A File instance.
- A Path instance.
- A Directory instance.
- A RegularFile instance.
- A URI or URL instance.
When running
configurations.driver.each {File file ->
loader.addURL(file.toURL())
}
driver is a custom configuration define as
configurations {
driver
}
dependencies {
driver 'org.drizzle.jdbc:drizzle-jdbc:1.3'
}
Please any ideas how to fix?
Fixed by using
sourceSets.main.output.resourcesDir = sourceSets.main.java.outputDir
sourceSets.test.output.resourcesDir = sourceSets.test.java.outputDir
Instead of
sourceSets.main.output.resourcesDir = sourceSets.main.output.classesDirs
sourceSets.test.output.resourcesDir= sourceSets.test.output.classesDirs

What version(s) of adjacent tools is(are) compatible with Spring XD?

Spring XD interacts with the following backing components:
Zookeeper
JDBC Datastore (MySql, Postgres, etc...)
RabbitMQ, Redis, or Kafka (Transport)
Redis (Analytics)
Is there any documentation on which versions of these technologies should be used when running Spring XD in Distributed Mode?
Presumably when new versions of Spring XD are released, the compatible versions of the adjacent technologies may change. Is this documented anywhere?
I found a dependency list in the build.gradle file in GitHub. This is from the master:
ext {
xdAdminUIVersion = '1.2.0.RELEASE'
// Not in IO
activemqVersion = '5.6.0'
apacheFtpServerVersion = '1.0.6'
args4jVersion = '2.0.16'
curatorVersion = '2.6.0'
equalsverifierVersion = '1.1.3'
ftpServerVersion = '1.0.6'
apacheSshdVersion = '0.10.1'
greenmailVersion = '1.3.1b'
httpClientVersion = '4.2.5'
jcloudsVersion = '1.7.0'
oracleToolsVersion = '1.2.2'
platformVersion = '1.0.1.RELEASE'
postgresqlVersion = '9.4-1201-jdbc41'
splunkVersion = '1.3.0'
springBatchAdminMgrVersion = '1.3.0.RELEASE'
springIntegrationSplunkVersion = '1.1.0.RELEASE'
springIntegrationKafkaVersion = '1.2.1.RELEASE'
kafkaVersion = '0.8.2.1'
springShellVersion = '1.1.0.RELEASE'
zookeeperVersion = '3.4.6'
sparkVersion = '1.2.1'
sparkScalaVersion = '2.10'
sqoopVersion = '1.4.5'
// Also in IO
nettyVersion = '3.7.0.Final' // N.B. Reactor depends on Netty 4
hadoopGuavaVersion = '11.0.2' // This is only used by the mini cluster in the spring-xd-batch-extension tests
cdh5GuavaVersion = '14.0.1' // This is only used by the CDH 5 module for the xd/lib/cdh5 classpath jars
oldGuavaVersion = '15.0' // This is only used by spring-xd-integration-test, IO uses version 17.0
guavaVersion = '16.0.1'
springDataHadoopBase = '2.2.0.RELEASE'
// //Reactor 1.1 is used in spring-xd-extension-batch transitively though spring integration
// reactor11xVersion = '1.1.5.RELEASE'
singleNodeServerProcess = new SingleNodeServerProcess()
}

Grails: SQLException: No suitable driver found for jdbc:oracle:thin

When I run my app in GGTS 3.6.2 using Grails 2.4.3 I've got a message:
Caused by SQLException: No suitable driver found for jdbc:oracle:thin:#server:port/OCI
->> 689 | getConnection in java.sql.DriverManager
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 247 | getConnection in ''
| 18 | <init> . in awtool.Controller
| 266 | run in java.util.concurrent.FutureTask
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run . . . in java.lang.Thread
Error |
Forked Grails VM exited with errorJava HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
I read many posts about this error and used some recommendations.
I added ojdbc6.jar to project /lib
also I added ojdbc6.jar at project Java Build Path using Add External JAR..
Java and Grails PATHs is OK
Is there is a way how I can resolve this problem ?
BuildConfig.groovy:
grails.servlet.version = "3.0" // Change depending on target container compliance (2.5 or 3.0)
grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
grails.project.work.dir = "target/work"
grails.project.target.level = 1.6
grails.project.source.level = 1.6
//grails.project.war.file = "target/${appName}-${appVersion}.war"
grails.project.fork = [
// configure settings for compilation JVM, note that if you alter the Groovy version forked compilation is required
compile: [maxMemory: 256, minMemory: 64, debug: false, maxPerm: 256, daemon:true],
// configure settings for the test-app JVM, uses the daemon by default
// test: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, daemon:true],
// configure settings for the run-app JVM
run: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false],
// configure settings for the run-war JVM
war: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false],
// configure settings for the Console UI JVM
console: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256]
]
grails.project.dependency.resolver = "maven" // or ivymaven
grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits("global") {
// specify dependency exclusions here; for example, uncomment this to disable ehcache:
// excludes 'ehcache'
}
log "error" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
checksums true // Whether to verify checksums on resolve
legacyResolve false // whether to do a secondary resolve on plugin installation, not advised and here for backwards compatibility
repositories {
inherits true // Whether to inherit repository definitions from plugins
grailsPlugins()
grailsHome()
mavenLocal()
grailsCentral()
mavenCentral()
// uncomment these (or add new ones) to enable remote dependency resolution from public Maven repositories
// mavenRepo "http://repository.codehaus.org"
// mavenRepo "http://download.java.net/maven/2/"
// mavenRepo "http://repository.jboss.com/maven2/"
mavenRepo "http://repo.spring.io/milestone/"
}
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.
runtime 'mysql:mysql-connector-java:5.1.34'
// runtime "com.oracle:ojdbc6:11.2.0.4"
// runtime 'org.postgresql:postgresql:9.3-1101-jdbc41'
test "org.grails:grails-datastore-test-support:1.0-grails-2.4"
}
plugins {
// plugins for the build system only
build ":tomcat:7.0.55"
// plugins for the compile step
compile ":scaffolding:2.1.2"
compile ':cache:1.1.7'
compile ":asset-pipeline:1.9.6"
compile ":spring-security-core:2.0-RC4"
compile ":spring-security-ldap:2.0-RC2"
compile ":force-ssl:1.0.0"
// plugins needed at runtime but not for compilation
runtime ":hibernate4:4.3.5.5" // or ":hibernate:3.6.10.17"
runtime ":database-migration:1.4.0"
runtime ":jquery:1.11.1"
// Uncomment these to enable additional asset-pipeline capabilities
//compile ":sass-asset-pipeline:1.9.0"
//compile ":less-asset-pipeline:1.10.0"
//compile ":coffee-asset-pipeline:1.8.0"
//compile ":handlebars-asset-pipeline:1.3.0.3"
}
}
grails.server.port.http=8088
DataSource.groovy
import groovy.sql.*
dataSource {
pooled = true
dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
driverClassName = "com.mysql.jdbc.Driver"
username = "login"
password = "pass"
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory'
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
url = "jdbc:mysql://server:port/login"
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:mysql://server:port/login"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:mysql://server:port/login"
}
}
}
"Add External JAR.." and other ways of adding to the IDE classpath aren't useful when using Grails - the IDEs build their classpaths from the Grails dependencies, so you only need to ensure that Grails has access.
When adding jars to the lib dir (which should be avoided in general, but is needed in this case because Oracle annoyingly refuses to put their driver jars in public repos) you need to run
grails compile --refresh-dependencies
to get it added to the classpath - Grails hasn't had auto-detection of jars in /lib for a while.
Once you do that, if you need the jar for compilation (you don't in this case) then refresh the IDE from Grails. In GGTS/STS you can do this by right-clicking the project root node in the tree on the left and selecting Grails Tools | Refresh Dependencies.
In addition to Burt's answer explaining how to get Grails to find your Oracle library, you need to change DataSource.groovy to connect to an Oracle database (it's currently configured for MySQL). You need to change it to something like:
dataSource {
pooled = true
driverClassName = "oracle.jdbc.driver.OracleDriver"
dialect = "org.hibernate.dialect.Oracle10gDialect"
dbCreate = "update"
url = 'jdbc:oracle:thin:#localhost:1521:mydb'
username = "root"
password = "password"
properties {
// See http://grails.org/doc/latest/guide/conf.html#dataSource for documentation
jmxEnabled = false
initialSize = 5
maxActive = 50
minIdle = 5
maxIdle = 25
maxWait = 10000
maxAge = 10 * 60000
timeBetweenEvictionRunsMillis = 5000
minEvictableIdleTimeMillis = 60000
validationQuery = "select 1 from dual"
validationQueryTimeout = 3
validationInterval = 15000
testOnBorrow = true
testWhileIdle = true
testOnReturn = false
jdbcInterceptors = "ConnectionState;StatementCache(max=200)"
defaultTransactionIsolation = Connection.TRANSACTION_READ_COMMITTED
}
}
hibernate {
flush.mode = 'manual'
cache.use_second_level_cache = true
cache.use_query_cache = true
cache.region.factory_class = "net.sf.ehcache.hibernate.EhCacheRegionFactory"
}
Replace mydb, root, and password with the name of your schema, and the username and password you'll use to access it.

How to debug parameters sent in Grails

Grails is so nice to append the parameters sent to console output in the case of an error:
2011-05-23 12:17:05,173 [http-8080-5] ERROR errors.GrailsExceptionResolver - Exception occurred when processing request: [POST] / - parameters:
maps: on
maps: on
maps: on
maps:
_isPublic:
description: test
name: set1
isPublic: on
Stacktrace follows:
...
But how can I tell it to always show me which parameters are sent (like in Rails, for example)?
My current log4j configuration looks as follows:
error 'org.codehaus.groovy.grails.web.servlet', // controllers
'org.codehaus.groovy.grails.web.pages', // GSP
'org.codehaus.groovy.grails.web.sitemesh', // layouts
'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
'org.codehaus.groovy.grails.web.mapping', // URL mapping
'org.codehaus.groovy.grails.commons', // core / classloading
'org.codehaus.groovy.grails.plugins', // plugins
'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
'org.springframework',
'org.hibernate',
'net.sf.ehcache.hibernate'
warn 'org.mortbay.log'
I don't believe Grails itself supports logging the request parameters for each request. However, you can easily implement this yourself in a filter:
package com.example
class MyFilters {
private static final log = org.apache.commons.logging.LogFactory.getLog(this)
def filters = {
paramLogger(controller:'*', action:'*') {
before = {
log.debug "request params: $params"
}
}
}
}
Remember to enable debug logging for this filter in `Config.groovy by adding
debug com.example
to the log4j closure
You probably want to get more output from org.codehaus.groovy.grails.web so set that one to a lower level (debug or trace)

Resources