Anonymous
Not logged in
Talk
Contributions
Log in
Request account
Rest of What I Know
Search
Editing
Publishing a JAR to S3
From Rest of What I Know
Namespaces
Page
Discussion
More
More
Page actions
Read
Edit
History
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
I couldn't find a single source of how to publish a JAR to S3. Here's an example of as minimal as I can imagine. You'll need a <code>build.gradle</code> that looks like this: <syntaxhighlight lang="groovy"> apply plugin: 'java' apply plugin: 'maven-publish' sourceCompatibility = 1.8 targetCompatibility = 1.8 group = 'dev.roshangeorge.my_package' version = '1.0' repositories { mavenCentral() } dependencies { implementation 'com.google.protobuf:protobuf-java:3.25.2' // for example } sourceSets { main { java { srcDirs = ['src/main/java'] } } } jar { manifest { attributes( 'Implementation-Title': 'My Package', 'Implementation-Version': version ) } // Include the compiled classes from all subdirectories from sourceSets.main.output // Define the name of the JAR file archiveFileName = 'my-package.jar' } buildscript { repositories { mavenCentral() } dependencies { classpath 'software.amazon.awssdk:s3:2.23.14' } } publishing { publications { mavenJava(MavenPublication) { from components.java // Metadata configuration for the pom.xml pom { name = 'My Package' description = 'Full of class files' } } } repositories { maven { name = 's3' url = uri("s3://dev-roshangeorge/java/") credentials(AwsCredentials) { // Unfortunately there's no way to make the plugin resolve automatically // unless you've got an IAM role, so rather than use env-vars, we'll just // use the default credentials provider explicitly def defaultCredentials = software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider.create().resolveCredentials(); accessKey defaultCredentials.accessKeyId secretKey defaultCredentials.secretAccessKey } } } } </syntaxhighlight> and a <code>settings.gradle</code> that looks like this: <syntaxhighlight lang="groovy"> rootProject.name = 'my_package' </syntaxhighlight> The hard part for me was that the AWS SDK wouldn't load my credentials from my <code>~/.aws/credentials</code> file. Things would work with env vars, but I couldn't get them to work with the credentials file, which is what I normally use. You should then be able to do the usual dependency stuff with: <syntaxhighlight lang="groovy"> implementation 'dev.roshangeorge:my_package:1.0' </syntaxhighlight> so long as your <code>build.gradle</code> has an entry like: <syntaxhighlight lang="groovy"> allprojects { repositories { mavenLocal() maven { url "s3://dev-roshangeorge/java/" credentials(AwsCredentials) { def defaultCredentials = software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider.create().resolveCredentials(); accessKey defaultCredentials.accessKeyId secretKey defaultCredentials.secretAccessKey } } } } </syntaxhighlight> for which you'll need an entry like: <syntaxhighlight lang="groovy"> buildscript { repositories { jcenter() maven { url "https://plugins.gradle.org/m2/" } } dependencies { // get JARs from S3 (this is the important part) classpath 'software.amazon.awssdk:s3:2.23.14' } } </syntaxhighlight> [[Category:Programming]] [[Category:Tips]]
Summary:
Please note that all contributions to Rest of What I Know are considered to be released under the Creative Commons Attribution-ShareAlike (see
Rest of What I Know:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Wiki tools
Wiki tools
Special pages
Page tools
Page tools
User page tools
More
What links here
Related changes
Page information
Page logs