Gradle how to exclude certain packages of dependent projects

Gradle how to exclude certain packages of dependent projects

When developing a Gradle-related project, I encountered the problem of how Gradle excludes certain packages of dependent projects, and the solution to related problems cannot be found on the Internet, which requires me to read the relevant parts of the official documentation carefully.

The official documentation describes it as follows:

To declare specific dependencies for a configuration, the following syntax can be used:

dependencies {
    
    
    configurationName dependencyNotation
}

To perform some advanced configuration on dependencies when declaring them, you can also pass a configuration closure:

dependencies {
    
    
    configurationName(dependencyNotation){
    
    
        configStatement1
        configStatement2
    }
}

case:

plugins {
    
    
    id 'java' // so that I can declare 'implementation' dependencies
}

dependencies {
    
    
  implementation('org.hibernate:hibernate:3.1') {
    
    
    //in case of versions conflict '3.1' version of hibernate wins:
    force = true

    //excluding a particular transitive dependency:
    exclude module: 'cglib' //by artifact name
    exclude group: 'org.jmock' //by group
    exclude group: 'org.unwanted', module: 'iAmBuggy' //by both name and group

    //disabling all transitive dependencies of this dependency
    transitive = false
  }
}

Project dependency syntax:

configurationName project(':some-project')

However, the above only mentioned examples of project dependencies, package dependencies, and package exclusion dependencies, and did not explain how to exclude packages in project dependencies. For details, see:
https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.dsl.DependencyHandler.html
After thinking about it for a while, I found that closures can solve this problem

dependencies {
    
    
	//使用闭包
    implementation (project(path: ':vblog-server-common')){
    
    
    	// 排除项目依赖
        exclude(group: 'com.github.pagehelper', module: 'pagehelper-spring-boot-starter')
        exclude(group: 'org.springframework.boot', module: 'spring-boot-starter-data-redis')
    }
    implementation 'org.springframework.boot:spring-boot-starter-data-elasticsearch'
}

I stayed here to check for a long time, and found that the grammar is not getting started. It is time to study Groovy and check the Gradle-related APIs carefully.

reference

Guess you like

Origin blog.csdn.net/HHoao/article/details/128499157