building test artifact using gradle build for a java project

I am new to gradle build, I am currently working on a migrating maven project to gradle. In maven i can build both src jar and also test jar of the project. How do i do the same thing in gradle.

Answers


In order to build the source jar, you don't have to do anything special

  1. Use java plugin : apply plugin: 'java'
  2. Call the jar task which is automatically added by the plugin

To build the test jar you can do something as follows:

Create a jar task that packs all your compiled test classes:

task jarTests(type : Jar) {
    from sourceSets.test.output
    archiveName "${baseName}-tests.jar"
} 

Then, make that new task dependent on the test task:

jarTests.dependsOn 'test'

Actually it can depends on the compileTestJava task, but you probably don't want it to succeed if you can compile your test classes but unable pass all test.

Now you can run the new jarTests task.

There are maybe shorter ways to do achieve this, which I'm unfamiliar of.


Need Your Help

What would be regular Expression for validating Date format like mm/yyyy.?

javascript jquery regex jquery-validate

What would be regular Expression for validating Date format like mm/yyyy. I am new to regular expressions