Last active
September 26, 2019 21:57
-
-
Save hlzhang/48860851bcb1c04432f3507bb20c2e5c to your computer and use it in GitHub Desktop.
Fix IDEA Intellij's issue "Module must not contain source root. The root already belongs to module". Intellij always add root module's src/main/resources into child modules in multi module maven projects and prevent me saving module config unless I remove them all manually. That's really sucks.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set -x | |
function fix_content_root() { | |
local in_directory="$1" | |
local targets=($(grep -E -l --include \*.iml '<content url="file://\$MODULE_DIR\$/(\.\./)+src/main/resources"' -r ${in_directory} | grep -v 'fixContentRoot.sh')) | |
for target in ${targets[@]}; do | |
echo ${target}; | |
sed -Ei 's#<content url="file://\$MODULE_DIR\$/(\.\./)+src/main/resources" />##g' ${target}; | |
sed -i '/<content url="file:\/\/$MODULE_DIR$\/..\/src\/main\/resources">/{:a;N;/<\/content>/!ba};/<sourceFolder url="file:\/\/$MODULE_DIR$\/..\/src\/main\/resources" type="java-resource" \/>/d' ${target}; | |
sed -i '/<content url="file:\/\/$MODULE_DIR$\/..\/..\/src\/main\/resources">/{:a;N;/<\/content>/!ba};/<sourceFolder url="file:\/\/$MODULE_DIR$\/..\/..\/src\/main\/resources" type="java-resource" \/>/d' ${target}; | |
sed -i '/<content url="file:\/\/$MODULE_DIR$\/..\/..\/..\/src\/main\/resources">/{:a;N;/<\/content>/!ba};/<sourceFolder url="file:\/\/$MODULE_DIR$\/..\/..\/..\/src\/main\/resources" type="java-resource" \/>/d' ${target}; | |
done | |
} | |
fix_content_root "${HOME}/Documents/IdeaProjects" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment