Home > Mobile >  gradle: api vs api project() difference
gradle: api vs api project() difference

Time:06-24

I am quite new to gradle but have good experience with maven. I am wondering what is the difference between these two below.

api project(':my-prj-1') 

vs

api "com.mydomain:grpc-helper:${grpc-helperVersion}"

I can see that when using project, i am giving just the project name not the artifactory details.

So when should or when can i use api project and what is the difference compared with just api. And in this case is there any comparison possible with Maven.

CodePudding user response:

(Sorry for my poor English)

I suppose you have a sub-project named my-prj-1 that can build the sub-artifact com.mydomain:grpc-helper.

By api project(':my-prj-1'), when you build the main project, the sub-project will also get built and its artifact will be used in the main project. (1)

By api "com.mydomain:grpc-helper:${grpc-helperVersion}", the main project will try to find the artifact from the repository only, if the sub-project is not built yet, the build will fail. (2)

From my experience, I would prefer the first approach since it a little bit safer. If the sub-artifact is already built then the sub-project build is skipped (due to incremental build) so there are no performance differences from the second approach.

  • Related