首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我想使用Gradle将存储库中的.ebextensions (AWS Beanstalk)目录复制到Java jar文件的根目录中

我想使用Gradle将存储库中的.ebextensions (AWS Beanstalk)目录复制到Java jar文件的根目录中
EN

Stack Overflow用户
提问于 2017-10-02 11:27:25
回答 1查看 464关注 0票数 1

我有一个Spring Boot项目,需要使用Gradle将.ebextensions文件夹从我的存储库中复制到jar文件的根(顶级)文件夹中。如果它不在jar文件的根目录中,我注意到AWS Beanstalk不会选择.ebextensions文件夹下的nginx conf文件。

也就是说,这个文件夹当前在repo中:

代码语言:javascript
复制
src
build.gradle
gradlew.bat
gradlew
build
README
.ebextensions

在我的build.gradle中,我有这样的代码:

代码语言:javascript
复制
jar {
   from('.')
   into("./.")
   include '.ebextensions/**'
}

但是,我发现.ebextensions文件夹最终将位于jar文件中的BOOT-INF/classes/下。它还将擦除所有其他类文件,否则这些文件将位于BOOT-INF/classes/下!

如何获得与BOOT-INF相同级别的目录?

代码语言:javascript
复制
.
..
BOOT-INF
WEB-INF
.ebextensions
<Rest of the source files here>

谢谢!

附注:我也尝试过下面的另一种解决方案,但也不起作用:

代码语言:javascript
复制
task copyEbExtensions(type: Copy) {
  from '.'
  into { getDestDir() }
  include '.ebextensions'
}

P.S.#2另外,这是我的build.gradle,以防对您有帮助:

代码语言:javascript
复制
buildscript {
    repositories {
       mavenCentral()
    }
    dependencies {
       classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.7.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'

jar {

   baseName = 'oneyearafter'
   version =  '0.1.26'
}



task copyEbExtensions(type: Copy) {
    from '.'
    into { getDestDir() }
    include '.ebextensions'
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.0'
}


repositories {
    mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    compile("org.springframework.boot:spring-boot-devtools")

    compile("org.springframework.boot:spring-boot-starter-web")
    // tag::actuator[]
    compile("org.springframework.boot:spring-boot-starter-actuator")
    // end::actuator[]
    // tag::tests[]

    compile("org.thymeleaf:thymeleaf-spring4")

    compile("org.springframework.boot:spring-boot-starter-security")

    // JPA Data (We are going to use Repositories, Entities, Hibernate, etc...)
    compile 'org.springframework.boot:spring-boot-starter-data-jpa'

    // Use MySQL Connector-J
    compile 'mysql:mysql-connector-java'


}


bootRun {
    addResources = true
}
EN

回答 1

Stack Overflow用户

发布于 2017-10-02 12:22:33

下面是我用于构建jar文件的自定义gradle函数。运行任务compileRunableJarFile编译jar文件。

代码语言:javascript
复制
apply plugin: 'java'

sourceSets {
    main {
        java {
            srcDir 'src/java'
        }
        resources {
            srcDir 'src'
            exclude 'src/java/**/*'
        }
    }
}

compileJava.dependsOn(processResources)
jar {
    duplicatesStrategy = 'exclude'
    manifest {
        attributes 'Implementation-Title': title,
                'Implementation-Version': version,
                'Implementation-Vendor': vendor,
                'Created-By': creator,
                'Main-Class': mainClass,
                'Manifest-Version': version,
                'Manifest-Title': title,
                'Application-Name': title,
                'JPA-PersistenceUnits': persistenceUnit
    }
}

//create a single Jar with all dependencies
task compileRunableJarFile(type: Jar, description: 'to create runable JAR.', group: 'compile') {
    manifest {
        attributes 'Implementation-Title': title,
                'Implementation-Version': version,
                'Implementation-Vendor': vendor,
                'Created-By': creator,
                'Main-Class': mainClass,
                'Manifest-Version': version,
                'Manifest-Title': title,
                'Application-Name': title,
                'JPA-PersistenceUnits': persistenceUnit
    }
    baseName = 'app_name_prefix-' + getCurrentTime()
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46519102

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档