0

I have Intellij IDEA's "Build Artifact" configured properly to generate an executable JAR containing resources, MANIFEST.MF,compiled classes, etc. But isn't Gradle supposed to manage that? I'm going to eventually need to use features in building that JAR that are unavailable from the Build Artifact GUI. How do I port the Build Artifact configs to a gradle.build file instead?

I see in IDEA > File > Settings... > Build, Execution, Deployment > Buld Tools > Gradle > [] Delegate IDE build/run actions to gradle, but that checkbox is disabled despite my project module having a build.gradle . And I'm not sure that feature does what I want.

aehndi
  • 3
  • 1
Matthew
  • 757
  • 11
  • 19

2 Answers2

0

IDE will not create jar artifacts automatically based on build.gradle files.

If you want to configure some specific aspects of artifacts from gradle scripts consider using gradle-idea-ext-plugin. See Artifacts DSL section of the plugin's documentation.

Andrey
  • 15,144
  • 25
  • 91
  • 187
  • But there is a Gradle task "jar" that will build a JAR as specified in build.gradle files. I can create a Run Configuration for that Gradle task with pre/post/etc configuration for execution integrated with IDEA, such as calling the debugger etc. – Matthew Jan 18 '19 at 23:00
  • Sure. I was talking about the Atifacts that one configures in IDE itself, see [Working with Artifacts](https://www.jetbrains.com/help/idea/working-with-artifacts.html#artifact_def). – Andrey Jan 19 '19 at 14:16
  • Yes, as I mentioned in the Question, I have the IDE's Build Artifacts configured correctly. I am looking for instructions to port the Build Artifacts behavior to a Gradle config, since Gradle has both the underlying features and the integration with the IDE's configs, GUI etc. Once ported to Gradle I would remove the IDE's native Build Artifacts configs. The point is to use only Gradle to manage builds. – Matthew Jan 20 '19 at 16:27
  • You want to create a jar? Then look into https://stackoverflow.com/questions/21721119/creating-runnable-jar-with-gradle – Andrey Jan 22 '19 at 09:26
  • What would answer my question would be instructions that explain which Gradle code directly corresponds to the settings in IDEA's Build Artifact feature. That's a lot more involved and specific than just building a JAR as per those instructions you linked to. – Matthew Jan 22 '19 at 22:23
  • It makes no sense, there is no direct mapping. – Andrey Jan 23 '19 at 07:37
  • I specifically asked for "porting". That's not "direct mapping" (except when extremely lucky), it takes a developer's skills. If you're just going to explain IDEA's direct IDE features, perhaps you can explain its feature `Delegate IDE build/run actions to gradle` . And why that checkbox is disabled despite my project module having a `build.gradle` . – Matthew Jan 24 '19 at 14:33
0

Add JAR Gradle-Task to your Run or Debug Configuration:

enter image description here

You'll find your JAR artifact in project's folder: Test/build/libs.

Zon
  • 18,610
  • 7
  • 91
  • 99