Downloading Dependences From Private Amazon S3 Repository with Gradle

♀尐吖头ヾ 提交于 2020-01-01 04:55:09

问题


I am looking to add Groovy support to an existing java project so that I can seemlessly compile mixed Java and Groovy code using invokedynamic so that I can get Java-like execution speed without needing to waste excessive amounts of time with verbose Java syntax

After reading that the gmaven plugin no longer supports compilation -and that the groovy eclipse compiler plugin doesn't yet support invokedynamic, I asked myself, why would I want to continue using Maven if it compiles Groovy code that is needlessly slow?

Consequently, I decided I would try scrapping maven for Gradle so that I could obtain faster code while also porting some python deployment scripts to Gradle tasks so as to only need one codebase.

I have some libraries stored on a simple password protected s3 maven repository (in order to avoid needing enterprise overkill like artifactory). After doing some basic research, I have found that Gradle has no built in support for adding in custom dependency management as determined by this stack overlow question and this support forums post.

I did manage to find a s3 plugin for gradle -but it doesn't deal with management of dependencies.

If the whole point of Gradle is to be more flexible than Maven and if the core purpose of a dependency management/ build system is to effectively manage dependencies from a variety of sources-then lack of support for custom repositories appears to be a fairly significant significant design flaw which makes any issues I have encounted with Maven thus far pale in comparison.

However, it is quite possible that I am missing something, and I have already invested several hours learning Gradle -so I figured I would see if there is some reasonable way to emulate dependency management for these s3 dependencies until Gradle developers fix this critical issue. Otherwise I will have to conclude that I am better off just using Maven and tolerating slower Groovy code until the compiler plugin supports invokedynamic.

Basically I need a solution that does the following:

  1. Downloads dependencies and transitive dependencies to the gradle cache
  2. Doesn't require me to hardcode the path to the gradle cache -so that my build script is platform independent.
  3. Doesn't download the dependencies again if they are already in the cache.
  4. Works with a multi-module project.

However, I cannot find anything in the documentation that would even give me a clue as to where to begin:


回答1:


Gradle 2.4 has native support for S3 repositories. Both downloading dependencies and publishing artifacts.

To download with IAM credentials (paraphrased from the link above):

repositories {
    maven {
        url "s3://someS3Bucket/path/to/repo/root"
        credentials(AwsCredentials) {
            accessKey 'access key'
            secretKey 'secret key'
        }
    }
}

Then specify your dependencies as usual.




回答2:


You don't need any custom repository support to make this work. Just declare a maven repository with the correct URL. If the repository works when used from Maven, it will also work with Gradle. (Uploading may be a different matter.)




回答3:


You can use S3 and http

repositories {
    mavenCentral()
    ivy {
        url "https://s3-eu-west-1.amazonaws.com/my-bucket"
        layout "pattern", {
            artifact "[artifact]-[revision].[ext]"
            m2compatible = true
        }
    }
}

Name the jar in S3 to name-rev.jar (joda-time-3.2.jar) in my-bucket. Also upload a pom file. And in S3 give all permission to Download the jar and pom.



来源:https://stackoverflow.com/questions/23447954/downloading-dependences-from-private-amazon-s3-repository-with-gradle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!