Skip to content

Create production-package.zip earlier in the process #5691

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

shanman190
Copy link
Contributor

What's changed?

Create the production-package.zip earlier in the process and make it available on the classpath for usage.

What's your motivation?

Improvements upon 49f19f5.

Anything in particular you'd like reviewers to focus on?

N/A

Anyone you would like to review specifically?

@knutwannheden

Have you considered any alternatives or workarounds?

N/A

Any additional context

N/A

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@shanman190 shanman190 requested a review from knutwannheden June 30, 2025 18:03
@shanman190 shanman190 self-assigned this Jun 30, 2025
@shanman190 shanman190 added the enhancement New feature or request label Jun 30, 2025
@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Jun 30, 2025
Copy link
Contributor Author

@shanman190 shanman190 left a comment

Choose a reason for hiding this comment

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

I'm double checking the licensing and source jar tasks yet, so that'll be just a moment for an update on those.

sourceSets {
main {
resources {
srcDir("src/main/generated-resources")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

callout: Should always avoid writing to the project directory as it can result in triggering tasks to run unnecessarily.

}
}

afterEvaluate {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

callout: Avoid afterEvaluate

@@ -8,7 +8,6 @@
"removeComments": true
},
"include": [
"src/**/*",
"test/**/*"
"src/**/*"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

callout: the tsc compiler isn't very smart, so what this was resulting in is the test/** sources being built twice which isn't desirable.

Copy link
Contributor

Choose a reason for hiding this comment

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

We'd still need some more refactoring to get rid of this. The problem is that some integration tests fail without this. The tests aren't executed on CI, so I can also fix this afterwards.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just a clarification, but as in the Java integration tests?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. They depend on a JS recipe which is in test. I will try to fix 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.

Alright, so how would you feel about adding an NPM script to compile tests separate from the test and ci:test phases. Then we can wire a dependency from integrationTest to this new task. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So we can take this thought a step further by using the jvm-test-suite plugin instead of the Nebula IntegTest plugin. With the jvm-test-suite plugin, we would be declaring a dependency upon the production outgoing artifacts which would result in the jar being built and more closely aligning the integration tests with what the real runtime environment would look like.

Copy link
Contributor Author

@shanman190 shanman190 left a comment

Choose a reason for hiding this comment

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

Licensing no longer required any changes because the resource is coming from the build directory rather than the project directory.

Source jar still needed it's dependency and exclusion (see further inline comments).

Comment on lines 181 to 196
sourceSets {
main {
resources {
srcDir(createProductionPackage.destinationDirectory)
}
}
}

tasks.named<Jar>("sourcesJar") {
from(createProductionPackage)
exclude("production-package.zip")
}

tasks.named<ProcessResources>("processResources") {
dependsOn(createProductionPackage)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

callout: All of this is really a hack to make the IDE work correctly. The production-package.zip is a generated resource that would normally be included into the binary jar itself. Unfortunately, since IDEA doesn't generate the jar, but rather uses the raw classes and resources, we're stuck with forcing the production-package.zip to be generated earlier in the process than would typically be necessary, including it as a main resource for IDE support, and then having to filter it out of other tasks for which we don't want the generated binary to be included for.

Overall, not ideal by any means.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can probably get rid of the hack and just require any IDE tests to specify the path to the dist dir of the project when setting up RPC. I think that is acceptable.

@shanman190
Copy link
Contributor Author

I had a couple of integration test failures on Windows, but pushed the changes here as it may be OS specific.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

2 participants