Enable Gradle native support programmatically

Answered

I have an ability to add dependency on test framework library programmatically: I need to call JavaProjectModelModificationService.addDependency method with framework library descriptors for it. After that there is the following code in my build.gradle file

dependencies {
implementation 'org.testng:testng:6.9.6'
implementation 'org.junit.jupiter:junit-jupiter:5.8.1'
}

But I would also like to add programmatically the following section to my build.gradle

test {
useJUnit()
useTestNG()
useJUnitPlatform()
}

What is the correct way to do it?

0
3 comments

There is currently no API for modifying existing Gradle build script for this use case. For creating Gradle build script from scratch there's org.jetbrains.plugins.gradle.frameworkSupport.buildscript.GradleBuildScriptBuilder.

0

Yann Cebron, thanks for your reply. Could you suggest another way to solve a problem with conflicts of added by our plugin tests dependencies in user's project, that has already been created with his own Gradle script?

0

If you mean checking for existing definition of dependencies, you could use com.intellij.externalSystem.ExternalDependencyModificator

0

Please sign in to leave a comment.