Move Package Refactoring

I have a project containing two modules, each with a source root and a test source root. I need to move part of a package (both sources and test sources) from one module to the other, keeping the sources and test sources separate in their respective roots. So this package, halfway down a package hierarchy in one module, needs to be moved to halfway down a different package hierarchy in the other module.

If I select the source package node in the Project view and drag it to its intended destination package directory, IDEA tells me that the test source files are part of that package and will also be copied there - but I want the test sources copied to the test source package hierarchy in the other module, not mixed in with the ordinary sources...

If I use the context menu 'Move' refactoring on the source package node, IDEA offers me 3 options - 'Move Package' (not suitable, as above), or ' Move Directory to Another Source Root', or 'Move Directory to Another Directory', both of which will create the entire package/directory hierarchy at the destination, not just from the selected package/directory down.

Does anyone know how I can move the source package subdirectory from the selected node to its destination subdirectory, without also copying the test sources to the same directory? I really don't want to create all the package subdirectories in the destination package by hand and move the files in them individually...

Any ideas?

1 comment
Comment actions Permalink

OK - I worked out a solution - I removed the test source root from the module before moving the source package, then added it back. Then I removed the source root from the module before moving the test sources package (remembering to add the source root back afterwards)...

An oddity when moving the packages - IDEA displays a file/memory cache conflict message for every file moved, that you have to choose which version to accept, file or memory. It would save a lot of clicking if there was an option to apply the first choice made to all files being moved.

0

Please sign in to leave a comment.