Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Gradle's dynamic versions and avoid betas?

I have this on my build.gradle:

testCompile(group: 'junit', name: 'junit', version: '4.+')

It resolves to:

junit:junit:4.+ -> 4.12-beta-1

I don't want to use beta releases but at the same time I want to use the dynamic version. in this case I want to depend on 4.11 .

Is it possible? How?

Note: Maven "versions" plugin - how to exclude alpha/beta versions from reponse? has an answer for maven but I'm not sure how to translate this in Gradle.

like image 521
Valentino Miazzo Avatar asked Jul 28 '14 12:07

Valentino Miazzo


People also ask

How do I specify the latest version of Gradle?

You can specify the Gradle version in either the File > Project Structure > Project menu in Android Studio, or update your Gradle version using the command line. The preferred way is to use the Gradle Wrapper command line tool, which updates the gradlew scripts.

What is transitive dependency in Gradle?

Transitive dependencyA variant of a component can have dependencies on other modules to work properly, so-called transitive dependencies. Releases of a module hosted on a repository can provide metadata to declare those transitive dependencies. By default, Gradle resolves transitive dependencies automatically.

What is dependency management in Gradle?

In most cases, a project relies on reusable functionality in the form of libraries or is broken up into individual components to compose a modularized system. Dependency management is a technique for declaring, resolving and using dependencies required by the project in an automated fashion.


1 Answers

You could use ComponentMeta to set the status:

dependencies {
   components {
     eachComponent { ComponentMetadataDetails details ->
         def version = details.id.version
         if (version.contains("beta") || version.contains("alpha")) {
             details.status = "milestone" // default in Gradle
         }
     }
   }
 }

Then use the status range syntax for your dependency:

testCompile(group: 'junit', name: 'junit', version: 'latest.release')

Now Gradle won't consider your beta a "release", and hence it won't match 4.12-beta-1. This won't let you only pick 4.x releases though, i.e. a 5.2 release would also apply.

like image 157
Justin Ryan Avatar answered Oct 17 '22 01:10

Justin Ryan