Skip to content

Fix projects that failed to build within Intellij #62258

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

Merged
merged 12 commits into from
Sep 15, 2020

Conversation

jakelandis
Copy link
Contributor

@jakelandis jakelandis commented Sep 10, 2020

This commit address some build failures from the perspective of Intellij.
These changes include:

  • changing an order of a dependency definition that seems to can cause Intellij build to fail.
  • introduction of an abstract class out of the test source set (seems to be an issue sharing
    classes cross projects with non-standard source sets.
  • a couple of missing dependency definitions (not sure how the command line worked prior to this)

This has been tested to work with
-> a clean checkout (clean -xdf) -> restart and invalidate cache -> rebuild project and no errors.

/** Runs rest tests against external cluster */
// TODO: Remove this timeout increase once this test suite is broken up
@TimeoutSuite(millis = 60 * TimeUnits.MINUTE)
public class AbstractXPackRestTest extends ESClientYamlSuiteTestCase {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are not any actual changes to this file...just renamed and moved back to the test source set.

I think this change this makes sense since independent of any other reason since there are a few runners that extend this... however the real reason i am introducing this is that I could not figure out how to get Intellij to share classes x-project and x-non-standard source set...it works fine from the test sourceset, but when shared from the custom source set (yamlRestTest) Intellij seems to have issues (the command line works fine).

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe that's due to setting up the source sets correctly. This should work, and we do it in other places.

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 believe that's due to setting up the source sets correctly. This should work, and we do it in other places.

I'm not sure I follow the comment... I tried a variety of ways to get Intellij to honor the configuration, it always works when defined in the test sourceset , but fails with identical config with a different sourceset name. I am sure I am missing something (or there is a bug in intellij), but not sure what. I don't believe it is related to the GradleUtils comment below since it is a different failure that addresses. Is there something specific you would like me to try ? I think this changes as-is actually a net positive change, with the benefit that it does not show red squiggly lines in Intellij.

from sourceSets.test.output
from sourceSets.yamlRestTest.output
from sourceSets.javaRestTest.output
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 am pretty sure the only reason we expose this is for the yaml tests and the custom parent runner, both of which are (now) in the test source set...so only expose that in the jar and testArtifact config.

@@ -155,7 +155,7 @@ public static void setupIdeForTestSourceSet(Project project, SourceSet testSourc
project.getPluginManager().withPlugin("idea", p -> {
IdeaModel idea = project.getExtensions().getByType(IdeaModel.class);
idea.getModule().setTestSourceDirs(testSourceSet.getJava().getSrcDirs());
idea.getModule().getScopes().put("TEST", Map.of("plus", List.of(runtimeClasspathConfiguration)));
idea.getModule().getScopes().put(testSourceSet.getName(), Map.of("plus", List.of(runtimeClasspathConfiguration)));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this doesn't seem to have any functional impact, just noticed I missed this before and I think it is a bit more correct.

@@ -1,8 +1,8 @@
apply plugin: 'elasticsearch.yaml-rest-test'

dependencies {
yamlRestTestImplementation project(path: xpackModule('core'), configuration: 'testArtifacts')
yamlRestTestImplementation project(path: xpackModule('core'))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

wierd dependency ordering thing...likely a subtle in Intellij

@jakelandis jakelandis changed the title Fix intellij build Fix projects that failed to build within Intellij Sep 10, 2020
@jakelandis jakelandis marked this pull request as ready for review September 10, 2020 23:05
@jakelandis
Copy link
Contributor Author

cc: @javanna @williamrandolph

@@ -2,6 +2,8 @@ apply plugin: 'elasticsearch.java-rest-test'

dependencies {
javaRestTestImplementation project(path: xpackProject('plugin').path, configuration: 'testArtifacts')
// let the javaRestTest see the classpath of main
javaRestTestImplementation project.sourceSets.main.runtimeClasspath
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be why intellij gets confused. Instead we should add sourcets.main.runtimeClasspath to sourcesets.javaRestTest.runtimeClasspath rather than wire this up as a filecollection dependency. Basically, we should use GradleUtils.extendSourceSet() here if we need javaRestTest to "extend from" main.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

relevant prior comment: https://github.com/elastic/elasticsearch/pull/59444/files/c89b5de16f777a00a7be76280565debd6014728f#diff-3f6ea6fd97c3537cc14d8d9f622aac7b

Are there any concerns with using GradleUtils here (and about 5 other places) ? Concerns with example project different from rest of the projects?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, since example projects are meant for external plugin authors to use as a baseline for their own projects. Internal use is not so much an issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done 87c2493

@jakelandis
Copy link
Contributor Author

@mark-vieira - ready for another pass. I had to add a method to GradleUtils that will re-load the classpath for a test task since these RestIntegTestTask's are eagerly created (as opposed to lazily like the internalClusterTests). d2aceef

Copy link
Contributor

@mark-vieira mark-vieira left a comment

Choose a reason for hiding this comment

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

👍

@jakelandis
Copy link
Contributor Author

Thanks @mark-vieira !

@jakelandis jakelandis merged commit 86660b0 into elastic:master Sep 15, 2020
@jakelandis jakelandis deleted the fix_intellij_build branch September 15, 2020 17:52
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (:Core/Infra/Build)

@elasticmachine elasticmachine added the Team:Core/Infra Meta label for core/infra team label Sep 15, 2020
jakelandis added a commit to jakelandis/elasticsearch that referenced this pull request Sep 15, 2020
This commit address some build failures from the perspective of Intellij.
These changes include:
* changing an order of a dependency definition that seems to can cause Intellij build to fail.
* introduction of an abstract class out of the test source set (seems to be an issue sharing
  classes cross projects with non-standard source sets.
* a couple of missing dependency definitions (not sure how the command line worked prior to this)
# Conflicts:
#	x-pack/qa/security-example-spi-extension/build.gradle
@williamrandolph
Copy link
Contributor

Thanks for this! I had been getting the build error, but this fixes the problem for me.

jakelandis added a commit that referenced this pull request Sep 17, 2020
)

This commit address some build failures from the perspective of Intellij.
These changes include:
* changing an order of a dependency definition that seems to can cause Intellij build to fail.
* introduction of an abstract class out of the test source set (seems to be an issue sharing 
  classes cross projects with non-standard source sets. 
* a couple of missing dependency definitions (not sure how the command line worked prior to this)
@mark-vieira mark-vieira added Team:Delivery Meta label for Delivery team and removed Team:Core/Infra Meta label for core/infra team labels Nov 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Delivery/Build Build or test infrastructure >non-issue Team:Delivery Meta label for Delivery team v7.10.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants