3

The recently released Eclipse Photon has a feature where it automatically lists libraries with scope set to test with the attribute "Visible only for test sources" set to yes and this can't be turned off.

Showing Maven test dependencies

The problem I am facing due to this, none of our Eclipse projects currently have the test source folder marked as test folder. Being a corporate environment I cannot go ahead and just update all the odd hundreds of projects. Furthermore Eclipse Photon is not yet officially supported in our org.

So, that means I end up with thousands of compilation errors in all the test folders, as their dependencies now are only available for folders marked as "test".

How do I turn off this feature?

AppleGrew
  • 9,302
  • 24
  • 80
  • 124
  • I don't think this can be turned off. But if you hit Alt+F5, the test source folders are configured correctly. Sharing the `.classpath` file, where this information is stored, should cause no harm for users of older Eclipse IDEs. If the `.classpath` file is under version control, the file must be updated sooner or later. – howlger Jul 04 '18 at 23:35

2 Answers2

3

See the Test sources section of the article "Eclipse Project Photon - New and Noteworthy":

...for projects and libraries there is an attribute Visible only for test sources. This setting also exists for classpath containers, and if it is set to Yes for one of these, this value will be used for all contained libraries and projects.

You can turn the setting on or off from {your project} > Properties under Java Build Path > Source by selecting the entry Contains test sources and clicking the Toggle button:

enter image description here

So you were already on the right screen for resolving the issue; just click the Source tab and set Contains test sources to No.

skomisa
  • 16,436
  • 7
  • 61
  • 102
  • 1
    Yes I noticed this and I don't want to do exactly that. That will change the `.classpath` file which is version controlled. I don't want to update the project configs of other teams. – AppleGrew Jul 05 '18 at 05:13
  • OK. I misread your post and thought that you were only asking how to turn off the setting, but what you really want to do is _completely disable the new feature_, right? If that can't be done, and I don't see how it can, then examine what changes are being made to the project config under Photon (which you should probably spend some time on regardless). As howlger suggests, the changes may be backward compatible so you can allow your Photon changes in version control. (i.e. You will be updating the project configs used by other teams, but those updates are harmless from their perspective.) – skomisa Jul 05 '18 at 06:12
  • 2
    When manually set, the m2e Maven plugin will simply revert this option on rebuild (Alt+F5) – Terran Jul 19 '18 at 15:40
3

I think you are actually using maven and the test dependencies are automatically set to be "Visible only for test sources" as part of m2e's "Maven Dependencies" classpath container.

If updating the .classpath files ( by right-clicking on the project and choosing "Maven" > "Update Project") isn't an option for you, you can downgrade the m2e-plugin by uninstalling it and installing an older version from http://download.eclipse.org/technology/m2e/releases/ (I've verified that 1.8.3.20180227-2137 works).

Update: In m2e 1.9.1, which you can install in Eclipse Photon by using "Check for Updates" and which is included in Eclipse 2018-09 (successor of Photon), you can disable test classpath separation by setting the maven property m2e.disableTestClasspathFlag to true. You can do that either on the project level by setting it in the individual pom.xml files or for the full workspace by adding it as a property of an active profile in a user settings.xml.

If you don't have a user setting.xml yet, create one with the following content and select it in Eclipse in Preferences > Maven > Users Settings as User Settings. Then right-click on the projects and choose "Maven" > "Update Project" for all projects.

 <?xml version="1.0" encoding="UTF-8"?>
    <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
        <profiles>
            <profile>
                <id>default</id>
                <properties>
                    <m2e.disableTestClasspathFlag>true</m2e.disableTestClasspathFlag>
                </properties>
            </profile>
        </profiles>
        <activeProfiles>
            <activeProfile>default</activeProfile>
        </activeProfiles>
    </settings>
Till Brychcy
  • 2,876
  • 1
  • 18
  • 28
  • 1
    Okay. I have now simply downgraded to Eclipse Oxygen itself. – AppleGrew Jul 05 '18 at 09:36
  • 1
    Doesn't work. The maven plugin simply ignores src/test/ folders in some projects / bundles. Whenever "Maven" > "Update Project" is executed, it is set back to "No". The plugin is completely broken. The only option is to revert the whole Eclipse back to Oxygen (= new installation). Do these people even test their updates? – Terran Jul 19 '18 at 15:36
  • @Terran, I'm not sure what you tried. The old m2e version doesn't know anything about the test-related settings, so both source folders and all dependencies in the "Maven Dependencies" container are treated as "main"-code, so compilation is the same as in Oxygen. – Till Brychcy Jul 19 '18 at 16:35
  • m2e should pick up what folder is src/main and which one is src/test. At least from from the pom.xml. You can't release a major IDE version that doesn't compile your code anymore with no option to fix it. – Terran Jul 20 '18 at 07:30
  • Note the current question is from a user where everything works, but he doesn't want to update the .classpath files. You seem to have a problem where something doesn't work. m2e uses maven's own code to query the pom, so the question is why it doesn't work. If you want help and can provide an example project that shows what doesn't work, please create a specific question here or better file a bug at https://bugs.eclipse.org/ and link it here. – Till Brychcy Jul 20 '18 at 07:59