Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import X-Ray Agent Plugin project #52

Merged
merged 13 commits into from
Aug 31, 2020
Merged

Conversation

willarmiros
Copy link
Contributor

@willarmiros willarmiros commented Aug 25, 2020

Description of changes:

  • Added X-Ray Agent project in plugin form
  • Migrated all build logic to Gradle, verified artifacts are created correctly and tests pass with gradle clean build
  • Prepared the packages to be published to maven central, and verified the publishing will work by staging a release
  • Removed the sample app subproject, which will be replaced with a more proper sample app in the future

This leaves the repo in an awkward, duplicated state, and I plan on removing all the legacy Maven subprojects in the near future. I'll also update travis later, the Gradle project isn't very testable by CI until Disco is released to maven central. Just didn't want to make this PR more bloated than it already is.

Might not be in the incredibly near future, but I plan on adding license, checkstyle, null checker, etc to keep parity with the SDK standards.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@willarmiros
Copy link
Contributor Author

Travis is failing because it's still testing the old, maven-based project. When Disco and 2.7.0 of the SDK are in maven central, I'll switch travis over to the new project.

Copy link
Contributor

@anuraaga anuraaga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looked at a couple of project build files and the top level

dependencies {
implementation("com.amazonaws:aws-xray-recorder-sdk-aws-sdk")
implementation("software.amazon.disco:disco-java-agent-api")
implementation(project(":aws-xray-agent"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would put project dependencies above non-project

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

testImplementation("org.powermock:powermock-module-junit4:2.0.7")
}

description = "AWS X-Ray Agent AWS SDK V1 auto-instrumentation library"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would put description at top, just below plugins block

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it

build.gradle.kts Outdated
}
named<ShadowJar>("shadowJar") {
// Suppress the "-all" suffix on the jar name, simply replace the default built jar instead
archiveClassifier.set(null as String?)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
archiveClassifier.set(null as String?)
archiveClassifier.set("")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will change.

build.gradle.kts Outdated
// Suppress the "-all" suffix on the jar name, simply replace the default built jar instead
archiveClassifier.set(null as String?)

dependsOn(named<Jar>("jar"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like your way better :) will change.

@@ -0,0 +1,7 @@
rootProject.name = "com.amazonaws.xray.agent"

include("aws-xray-agent")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid having projects with subprojects, it's easy to mess up Gradle's caching if files in the subproject change. Maybe just have aws-xray-agent-plugin at the top level

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was copying the Disco project structure, e.g. https://github.com/awslabs/disco/tree/master/disco-java-agent-sql

But I suppose that's more applicable since they have several library-plugin subprojects. I think our repo could be flat without issue.

build.gradle.kts Outdated
// Otherwise, just publish the standard JAR
plugins.withId("java") {
if (plugins.hasPlugin("com.github.johnrengelman.shadow")) {
artifact(tasks.named<Jar>("jar").get())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the shaded artifact?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, although I think this actually might have to be wrapped in afterExecute for the hasPlugin to work. I'll add that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there something you noticed awry?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry should have been explicit - it's referring to "jar" task, not "shadowJar" task

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of afterEvaluate, you can just use plugins.WithId("com.github.johnrengelman.shadow")

Copy link
Contributor Author

@willarmiros willarmiros Aug 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I thought about this but I couldn't figure out a way to get gradle to behave differently if a plugin wasn't present. E.g. something like:

plugins.withId("shadow") {
  artifact()
}

plugins.withoutId("shadow") {
  from(components["java"])
}

The afterEvaluate + hasPlugin approach worked, but let me know if there's a preferable withId way instead.

build.gradle.kts Outdated
// Otherwise, just publish the standard JAR
plugins.withId("java") {
afterEvaluate {
if (plugins.hasPlugin("com.github.johnrengelman.shadow")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I think since we replace the jar (disable default task, use the empty classifier), actually components["java"] picks up the shadow jar. Appears to be working here

https://github.com/anuraaga/aws-opentelemetry-java-instrumentation/blob/master/build.gradle.kts#L111

Feels a bit hacky admittedly, but it makes sure the doc / source jars are published too which I think is requirement of maven central. With this approach we need to make sure to add those

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nice that worked for me too! Added the simplification.

@willarmiros willarmiros merged commit 44b55ff into aws:master Aug 31, 2020
@willarmiros willarmiros deleted the gradle-kotlin branch August 31, 2020 03:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants