Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8698193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:40:48+00:00 2026-06-13T01:40:48+00:00

How do I cleanly separate tasks that might require two different configuration tasks in

  • 0

How do I cleanly separate tasks that might require two different configuration tasks in Gradle? I’m attempting to separate the actual tasks that I want to execute in a buildSrc/dbhelpertasks.gradle file from the parent build.gradle file. build.gradle will contain partially configured tasks that are used in dbhelpertasks.gradle.

I have a number of different databases that I want to connect and execute SQL on so I created a SQLServerTask that takes a database name and URL.

Custom SQLServerTask.groovy

import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction
import groovy.sql.Sql


class SQLServerTask extends DefaultTask {
    def hostname
    def database
    def port = 1433
    def username
    def password
    def sql
    def sqlServerDriver = 'net.sourceforge.jtds.jdbc.Driver'

    @TaskAction
    def executeSql() {
        url = hostname + ":" + port + "/" + database
        databaseConnProps = [user: username, password: password]
        def sqlInstance = Sql.newInstance(url, databaseConnProps, sqlServerDriver)
        println "I would execute " + sql
    }

}

I then created a task in my build.gradle that would configure the SQLServerTask with some of the properties.

build.gradle

import groovy.sql.Sql
apply from: 'buildSrc/dbhelpertasks.gradle'
repositories { 
    mavenCentral()
}

configurations {
    driver
}

dependencies {
    driver group: 'net.sourceforge.jtds', name: "jtds", version: "1.2.4"
}

//Load up all the drivers for use in this project
URLClassLoader loader = GroovyObject.class.classLoader
configurations.driver.each {File file ->
    loader.addURL(file.toURL())
}

task contentDbTask(type: SQLServerTask) {
    println "Configuring content db task"
    hostname = contentDbUrl
    database = contentDbName
    username = contentDbUserName
    password = contentDbPassword
}

The dbhelpertasks.gradle file contains the final configuration (SQL Statement) of the actual tasks that I want to execute.

buildSrc/dbhelpertasks.gradle

task getSiteParams(type: contentDbTask) {
    println "Configuring Site Params Task"
    sql = "SELECT * FROM CMS_SITE_PARAM"
}

When I execute gradle getSiteParams it ends up failing

* What went wrong:
A problem occurred evaluating script.
> Could not find property 'contentDbTask' on root project 'shipyard'.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:40:49+00:00Added an answer on June 13, 2026 at 1:40 am

    There are a number of misconceptions here.

    First, only class SQLServerTask should be in buildSrc, as the only purpose of buildSrc is to produce classes which are then used by the main build.

    dbhelpertasks.grovvy would typically go into a top-level gradle directory (sibling of buildSrc) and end in .gradle. Preconfiguration of a task, like contentDbTask does, would typically be done by a plugin (like the dbhelpertasks.gradle script plugin) rather than a task.

    A task’s type is always a class, so task getSiteParams(type: contentDbTask) won’t work. Also, dbhelpertasks.groovy can’t see tasks added (or any other configuraion done) by build.gradle, only the other way around. This is because the latter applies the former at the very top (which is fine).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a few problems breaking out an MsBuild package+deploy command into two separate
I have two Activities that both list items in a table. For the time
I have a list of objects (musical notes) that is enumerated on a separate
Is it possible to cleanly select only the current clicked div and not children
In order to cleanly port my game to the iPhone, I'm trying to make
How can I write this code more cleanly/concisely? /// <summary> /// Creates a set
How can I do this cleanly without gotos? loop: if(condition1){ something(); } else if
Clearly, when GROUP BY clause used, columns that are not aggregate function should be
While designing a C++ class, suppose I have following two options: Option 1: One
My current project is to write a program that basically is a cash register

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.