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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:17:37+00:00 2026-06-12T10:17:37+00:00

I have a task that generates java sources and a set of jars from

  • 0

I have a task that generates java sources and a set of jars from these sources (say, project a). I would like to export these jars to dependent projects (say, project b). So here’s roughly what I have right now:

//a.gradle

configurations{
  generatedJars
}

task generateJars(type: JavaExec) { 
  //generate jars ... 

  outputs.files += //append generated jars here
} 

dependencies{
  generatedJars generateJars.outputs.files
}


//b.gradle

dependencies{
  project(path: ':a', configuration: 'generatedJars')
}

It works OK, except that adding generateJars.outputs.files as a dependency does not tell gradle that it has to run generateJars task when there are no jars generated yet. I have tried adding the task itself as a dependency hoping that it would work in the same way as it does when you add a jar/zip task to an artifact configuration (e.g. artifacts{ myJarTask }), but it throws an error telling me that I cannot do that. Of course I can inject the generateJars task somewhere in the build process before :b starts evaluating, but that’s clumsy and brittle, so I would like to avoid it.

I feel like I should be adding the generated jars to artifacts{ ... } of the project, but I am not sure how to make them then visible to dependent projects. Is there a better way of achieving this?

Dependent projects (project b) will need to do setup IntelliJ IDEA module classpath to point to project a‘s generated jars. Something rather like this (pseudo-code):

//b.gradle

idea{
  module{
    scopes.COMPILE.plus += project(path: ':a', configuration: 'generatedJars').files
  }
}

So far I have tried simply adding a project dependecy on :a‘s generatedJars in :b, but Idea plugin simply adds module :a as a module-dependency and assumes that it exports its generated jars (which is probably a correct assumption), therefore not adding the generated jars to :b‘s classpath.

Any help would be greatly appreciated!

  • 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-12T10:17:37+00:00Added an answer on June 12, 2026 at 10:17 am

    First, do you need a separate configuration? That is, do you have clients of a that should not see the generated Jars? If not, you can add the generated Jars to the archives configuration, which will simplify things.

    Second, the correct way to add the generated Jars to the configuration is (instead of the dependencies block):

    artifacts {
        generatedJars generateJars
    }
    

    This should make sure that the generateJars task gets run automatically when needed.

    Third, I’d omit the += after outputs.files, although it might not make a difference. You should also add the necessary inputs.

    Fourth, why do you need a JavaExec task to generate the Jars? Can you instead add the generated sources to some source set and let Gradle build them?

    Fifth, IDEA doesn’t have a concept corresponding to Gradle’s project configuration dependencies. Either an IDEA module fully depends on another module, or not at all. You have two options: either use a module dependency and make the generated sources a source folder of the depended-on module (preferably both in the Gradle and the IDEA build), or pass the generated Jars as external dependencies to IDEA. In either case, you should probably add a task dependency from ideaModule to the appropriate generation task. If this still doesn’t lead to a satisfactory IDEA setup, you could think about moving the generation of the Jars into a separate subproject.

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

Sidebar

Related Questions

My Task: I have a Java Application that writes text files. These files should
I have a Symfony task that generates some files calls exec to a jar
I have a project that is laid out as follows: src/ java generated src/java
I have a task that runs periodically 10 second. I do some picturebox refreshing
I have a task that takes a rather long time and should run in
I have a task that's driving me crazy because i have no clue where
Just stumbled upon propertyGrid and its awesome! However, i have one task that i
I have a periodic task that needs to execute once a minute (using delayed_job).
I have an MSBuild task that executes (among other things) a call to xcopy.
I have a scheduled task that is very IO intensive (deleting hundreds of thousands

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.