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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:22:52+00:00 2026-06-10T02:22:52+00:00

Was trying to call out to the Saga Javascript code coverage from Gradle. After

  • 0

Was trying to call out to the Saga Javascript code coverage from Gradle. After a long time playing with it, I was finally able to get it working. However, I am new to gradle and don’t know if the way I did it makes the most sense or not! It seems like there might be quite a few ways to do this, so I thought I would post what I did here in the hopes that I might learn if this way was okay or if there was a better way.

After downloading the saga-core from maven central, it turns out that there is no Java “main”. So I didn’t think I could easily use JavaExec. It looked to me that I needed to create a Java object, set some params, and call the “run” method provided.

Here is the final build.gradle I ended up with:

apply plugin: 'groovy'

buildscript {    
    repositories {
        mavenCentral()
    }

    dependencies {
        // add the jar file withe the code you want to execute to gradle's classpath
        classpath 'com.github.timurstrekalov:saga-core:1.1.2'
    }
}

configurations {
    compile
    codeCoverageTask
}

dependencies {
    groovy localGroovy()
    codeCoverageTask 'com.github.timurstrekalov:saga-core:1.1.2'
}

// I thought this was simple and made sense to be co-located here rather than
// another file...
// getting the imports to compile requires adding the "buildscript" section above
import java.io.File
import com.github.timurstrekalov.saga.core.CoverageGenerator

class SagaCoverageTask extends DefaultTask {
    def outputDirectory
    def baseDirectory
    def includes = 'my_includesPattern_here'
    def excludes = 'my_excludesPattern_here'
    def noInstrumentPatterns = [ 'my_noIntrumentPatterns_here' ]

    @TaskAction
    def runCoverage() {
        // check these were set correctly!
        println outputDirectory
        println 'baseDir' + baseDirectory

        // create an instance of the object
        CoverageGenerator generator = new CoverageGenerator(baseDirectory, includes, excludes, outputDirectory)   
        generator.noInstrumentPatterns = noInstrumentPatterns
        // there are params, but they would be handled in the same way if needed
        generator.run()   // invoke the arbitrary method
    }
}

task genCodeCoverage(type: SagaCoverageTask)  {
    // needed the values of task properties, so these are set here
    outputDirectory = new File('' + reportsDir + '/coverage')
    baseDirectory = new File('' + projectDir + '/src')   
}
  • 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-10T02:22:53+00:00Added an answer on June 10, 2026 at 2:22 am

    Looks like a decent start. File objects should generally be created with the project.file() method because it handles relative paths better than new File() (although it’s not a problem in this particular case). For example: file("$reportsDir/coverage").

    If the task class grows bigger or you want to reuse it across projects/builds, you should move it somewhere else (e.g. into buildSrc) and add some test coverage.

    By annotating the task class properties with @InputDirectory, @OutputDirectory, etc. you can make it so that the task will only run if some input has changed or previously generated output isn’t available anymore. This can speed up the build.

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

Sidebar

Related Questions

I am trying to call c# function from javascript the code i have tried
I am trying to call out to a legacy dll compiled from FORTRAN code.
I'm trying to call Calendar from my simple application in iPhone. all sample out
I am trying to call API from the website and print out the JSON
I'm trying to call a Restful service from a Silverlight 4 Out of browser
I'm testing out WPF for the first time and I'm trying to call a
I'm trying to work out what a BizTalk call to a web service is
Trying to call a SAP SOAP Web Service from a generated sudzc app shows
Im trying to call a method that will add or subtract 1 from a
I'm trying to call a method from another class with a simple button in

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.