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 8251509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:15:37+00:00 2026-06-08T00:15:37+00:00

I am trying to move a simple Groovy project to Gradle. I was mostly

  • 0

I am trying to move a simple Groovy project to Gradle. I was mostly able to configure the project, but I do not know how to deal with external resources.

Basically, my application needs to access a configuration file in JSON. Before moving to Gradle, I used to pass the location of this JSON file on the command line. I had made a simple bash script to call the main class with the correct path for the resource.

With Gradle if I understand correctly, I should be able to move this file into src/main/resources/ and have it available somehow from the Groovy classes. Question is: how?

EDIT

If I understand correctly, the resource should end in the JAR that gets built. My dir structure is like

src
  main
    groovy
      orgName
        packageName
          source.groovy
    resources
      orgName
        packageName
          config.json

But I do not see the resource inside the packageName.jar that is generated in the build directory

  • 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-08T00:15:38+00:00Added an answer on June 8, 2026 at 12:15 am

    I knocked up a quick example… Given this directory structure:

    .
    |-- src
    |    |-- main
    |         |-- groovy
    |         |    \-- org
    |         |         |-- Test.groovy
    |         \-- resources
    |              \-- config.json
    \-- build.gradle
    

    Where Test.groovy is:

    package org
    
    import groovy.json.*
    
    public class Test {
      static main( args ) {
        def slurper = new JsonSlurper()
        def config = slurper.parseText( Test.class.getResource( '/config.json' ).text )
        println "Args were $args, config is $config"
      }
    }
    

    config.json is:

    {
      "data": true
    }
    

    and build.gradle is:

    apply plugin: 'groovy'
    
    repositories {
      mavenCentral()
    }
    
    dependencies {
      groovy 'org.codehaus.groovy:groovy-all:2.0.0'
    }
    
    task runTest ( dependsOn: 'classes', type: JavaExec ) {
      main = 'org.Test'
      classpath = sourceSets.main.runtimeClasspath
      args 'ARG1'
    }
    

    You should just be able to run gradle runTest and it should just work…

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

Sidebar

Related Questions

I have made simple encryption/decryption method in php that I'm trying to move to
I'm trying to write a simple script that will move files in a list
I have this slideshow that I'm trying to simply move up, but I can't
I am trying to move some files in python, but they have spaces in
I am trying a simple move as shown below and get the following error:
Trying to do a simple drag and drop example in HTML5 - but when
I'm trying to write a simple pygame program where some boxes move around on
I come from a mostly n-tier background, and I'm trying to move more towards
I am trying move a very simple code first example from my local SQL
I'm trying to move a fairly slow function off of the main thread, but

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.