zoukankan      html  css  js  c++  java
  • gradles理解和文件配置

    gradle

    gradle tasks :查看所有的taske命令

    bootJar:打包,讲项目的所有依赖和主工程代码打包,一个可直接执行的一个包,不需要tomcat运行

    gradle使用bootjar打包后后,解压出来的三个目录

    BOOT-INF:

    ​ classes:存放java文件编译后的class文件

    ​ lib:所有的lib依赖包

    META-INF:

    ​ MANIFEST.MF:清单文件,描述当前项目可执行的一些信息

    org/

    ​ springframework/

    ​ boot/

    ​ loader/: 打包jar包,没有显现的加入在第三方jiar包中,默认通过网络拉取下载,loader文件中JarLauncher.class文件中设置了jar包运行时的入口和打包 后文件的结构(定义了BOOT-INF,META-INF中放什么数据)

    public class JarLauncher extends ExecutableArchiveLauncher {
        private static final String DEFAULT_CLASSPATH_INDEX_LOCATION = "BOOT-INF/classpath.idx";
        static final EntryFilter NESTED_ARCHIVE_ENTRY_FILTER = (entry) -> {
            return entry.isDirectory() ? entry.getName().equals("BOOT-INF/classes/") : entry.getName().startsWith("BOOT-INF/lib/");
        };
    
        public JarLauncher() {
        }
    
        protected JarLauncher(Archive archive) {
            super(archive);
        }
    
        protected ClassPathIndexFile getClassPathIndex(Archive archive) throws IOException {
            if (archive instanceof ExplodedArchive) {
                String location = this.getClassPathIndexFileLocation(archive);
                return ClassPathIndexFile.loadIfPossible(archive.getUrl(), location);
            } else {
                return super.getClassPathIndex(archive);
            }
        }
    
        private String getClassPathIndexFileLocation(Archive archive) throws IOException {
            Manifest manifest = archive.getManifest();
            Attributes attributes = manifest != null ? manifest.getMainAttributes() : null;
            String location = attributes != null ? attributes.getValue("Spring-Boot-Classpath-Index") : null;
            return location != null ? location : "BOOT-INF/classpath.idx";
        }
    
        protected boolean isPostProcessingClassPathArchives() {
            return false;
        }
    
        protected boolean isSearchCandidate(Entry entry) {
            return entry.getName().startsWith("BOOT-INF/");
        }
    
        protected boolean isNestedArchive(Entry entry) {
            return NESTED_ARCHIVE_ENTRY_FILTER.matches(entry);
        }
    
        public static void main(String[] args) throws Exception {
            (new JarLauncher()).launch(args);
        }
    }
    

    配置文件说明

    //相当于plugins{}
    //开发语言
    apply plugin :"java"
    //    打包方式
    apply plugin :"war"
    //下载idea相关插件
    apply plugin: "idea"
    //maven的相关插件
    apply plugin: "maven"
    
    apply plugin: 'org.akhikhl.gretty'
    
    //apply from: 'https://raw.github.com/akhikhl/gretty/master/pluginScripts/gretty.plugin'
    
    buildscript {
        repositories {
            mavenCentral()
        }
    
        dependencies {
            classpath 'org.akhikhl.gretty:gretty:2.0.0'
        }
    }
    
    repositories {
        mavenCentral()
    }
    
    if (!project.plugins.findPlugin(org.akhikhl.gretty.GrettyPlugin))
        project.apply(plugin: org.akhikhl.gretty.GrettyPlugin)
    
    
    
    
    //配置服务器相关属性   tomcat
    /*buildscript {
        repositories {
            mavenCentral()
        }
        dependencies{
            classpath 'org.zkhikhl.gretty:gretty:2.0.0'
        }
    }
    repositories {
        mavenCentral()
    }
    if (!project.plugins.findPlugin(org.akhikhl.gretty.GretyPlugin))
        project.apply (plugin: org.akhikhl.gretty.GretyPlugin)
    //配置tomcat的属性*/
    
    
    gretty {
        //    端口号
        httpPort = 8080
    //    项目名
        contextPath = '/mygradle'
        host = 'localhost'
        httpEnabled = true
    //    servlet的容器
        servletContainer = 'tomcat8'
    //    热部署
        scanInterval = 1
    //    检测是否发生修改,修改立刻生效
        fastReload = true
    //    日志级别
        loggingLevel = 'DEBUG'
    //    日治在哪里显示,在控制台显示
        consoleLogEnabled = true
        // ... many more properties
    
        //调试配置   监听端口   需要在Run-->Edit-->添加remote-->修改监听端口 默认5005
        //
        debugPort = 8888
        debugSuspend = true
    }
    
    
    /*
    plugins {
        //开发语言
        id 'java'
    //    打包方式
        id 'war'
    }*/
    
    group 'com.zhang'
    version '1.0-SNAPSHOT'
    //指定java的jdk
    sourceCompatibility = 1.8
    targetCompatibility = 1.8
    
    repositories {
    //    依赖下载仓库:这里是maven仓库
        mavenCentral()
    }
    //指定依赖包下载私服
    /*dependencies{
        repositories {
            maven{
                url:制定的ip地址
            }
        }
    }*/
    
    //jar包
    dependencies {
        testCompile group: 'junit', name: 'junit', version: '4.12'
    }
    //设置项目的各个阶段的编码
    tasks.withType(JavaCompile){
        options.encoding = "UTF-8"
    }
    [compileJava,javadoc,compileTestJava]*.options*.encoding ="UTF-8"
    
  • 相关阅读:
    验证整数 Double 转 int 两种写法
    0 can't find referenced pointcut declarePointExpress
    nested exception is java.lang.IllegalArgumentException: Pointcut is not well-formed
    org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML doc
    嵌入式系统(胡威)2019年春第一次作业 参考答案
    PAT(B) 1021 个位数统计(Java)
    PAT(B) 1020 月饼(Java)
    PAT(B) 1019 数字黑洞(Java)
    PAT(B) 1018 锤子剪刀布(C:20分,Java:18分)
    PAT(B) 1017 A除以B(Java)
  • 原文地址:https://www.cnblogs.com/baroque/p/12990106.html
Copyright © 2011-2022 走看看