Intellij maven dependency prefer local code

前端 未结 6 2223
野趣味
野趣味 2020-12-30 09:28

i\'m working on a project in which i have an android application project which has pom dependencies on other projects something like this:



        
6条回答
  •  生来不讨喜
    2020-12-30 09:44

    Just a small hint how to do the same with Gradle. Supposing you have two workspaces with lib and app. The lib is deployed to some maven repo and needs to be described in the following way:

    // build.gradle
    group 'lib.group'
    version 'lib.version'
    
    // settings.gradle
    rootProject.name = 'lib.name'
    

    While app dependencies are the following:

    // build.gradle
    compile "lib.group:lib.name:lib.version"
    

    So, the app module uses lib as a maven dependency. Now, you can import lib sources into app workspace using File | New | Module from existing sources. After refreshing the project from Gradle tool window, you will get two modules lib and app in the app workspace. However, even after reimporting Gradle the lib dependency will still point to the maven repository, what you can check in File | Project Structure.

    The trick to be done here is to click with the right mouse button on app module in the Gradle tool window, and select Composite Build Configuration option. Then, on the popup window just select the local lib module to include it in the app module build. Now, after reimporting Gradle deps again for the whole workspace you will get the maven dependencies for lib replaced with the local dependency.

提交回复
热议问题