Gradle 플러그 인 만 들 기

  • Gradle 프로젝트 창설
    apply plugin: ‘groovy’ //     java  ,    java
    
    apply plugin: ‘maven’ //    ;    jar    
    
    version = 1.0
    group = 'com.zjzhai'
    archivesBaseName = 'jshint-gradle'
    repositories.mavenCentral()
    
  • 가입 의존
    dependencies {
        compile(
                gradleApi() 
        )
    }
    
  • gradle 플러그 인 클래스 구현
        class JshintPlugin implements Plugin<Project>{
    
            void apply(Project project) {
                  //     .....
    
                  //     。jshint   
                  project.extensions.create("jshint", JshintConfig)
    
                 project.task('jshint') << {
    
                    // task  
                    // println     
    
                    if (hasError) {
                         //    ,     
                        throw new RuntimeException("Jshint Failure!")
                    }
                }
            }
        }
    
    `project.task('jshint')`  `jshint`         task 。
    
  • 플러그 인 입 구 를 정의 합 니 다.src/main/resources/META-INF/gradle-plugins/에 properties 파일 을 추가 합 니 다.jshint-gradle.properties파일.jshint-gradle플러그 인 이름 입 니 다.이 플러그 인 을 사용 할 때apple plugin 'jshint-gradle'입 니 다.파일 에서 입 구 를 정의 합 니 다:'implementation-class=com.zjzhai.gradle.jshint.JshintPlugin'
  • 패키지 업로드
    uploadArchives {
        repositories.mavenDeployer {
            repository(url: 'file:/Users/xxxx/.m2/repository')
        }
    }
    
    url 지정 창고 주소 실행 명령 업로드:gradle uploadArchives
  • 플러그 인
    apply plugin: 'jshint-gradle'
    jshint {
        inputDirs = file('src/main/resources').path
        includes = ["asset/*.js"]
        excludes = ["**/compase/*.js"]
    }
    
    경 로 를 사용 하 는 것 은 ant path 문법 을 사용 하면 여기jshintproject.extensions.create("jshint", JshintConfig)의 대응 을 볼 수 있 습 니 다.JshintConfig 클래스 는 Bean:
        class JshintConfig {
            def inputDirs
            def includes
            def excludes
    
        }
    
    사용 시 명령:gradle jshint
  • JShint Gradle 플러그 인 소스 주소

    좋은 웹페이지 즐겨찾기