Idea plugin and absolute path to flatdir dependencies on linux


(Daniel Svojanovský) #1

Hi,

I would like to be able to generate idea project files either on linux or windows. It must not matter where you generate files I want to be able use the project files on both platforms. E.g.:

  1. run gradle idea on linux 2. open idea project files on windows (shared folder with linux machine).

I have following project structure:

├── mod1
│   └── lib
│  
   └── hamcrest-all-1.2.jar
├── mod2
│   └── lib
│  
   └── httpclient-4.2.1.jar
├── build.gradle
└── settings.gradle

And corresponding build script:

allprojects {
 apply plugin: 'java'
 apply plugin: 'idea'
}
  subprojects {
 repositories {
  flatDir(name: 'repo1', dirs: "${rootDir}/mod1/lib")
  flatDir(name: 'repo2', dirs: "${rootDir}/mod2/lib")
 }
  }
  project(':mod1') {
 dependencies {
   compile 'org.apache.httpcomponents:httpclient:4.2.1'
  compile 'org.hamcrest:hamcrest-all:1.2'
 }
}
  project(':mod2') {
 dependencies {
   compile 'org.apache.httpcomponents:httpclient:4.2.1'
  compile 'org.hamcrest:hamcrest-all:1.2'
 }
}

My problem is that if I generate idea project files on linux I will endup with absolute paths pointing to repository in another module lib folder.

This is .iml file when I generate project on linux (wrong beacuse the second path is not valid on windows):

<orderEntry type="module-library" exported="">
  <library>
    <CLASSES>
      <root url="jar://$MODULE_DIR$/lib/httpclient-4.2.1.jar!/"/>
    </CLASSES>
    <JAVADOC/>
    <SOURCES/>
  </library>
</orderEntry>
<orderEntry type="module-library" exported="">
  <library>
    <CLASSES>
      <root url="jar:///mnt/hgfs/shared/idea-absolute/mod1/lib/hamcrest-all-1.2.jar!/"/>
    </CLASSES>
    <JAVADOC/>
    <SOURCES/>
  </library>
</orderEntry>

This is .iml file when I generate project on windows (correct, it uses path relative to $MODULE_DIR$):

<orderEntry type="module-library" exported="">
  <library>
    <CLASSES>
      <root url="jar://$MODULE_DIR$/lib/httpclient-4.2.1.jar!/" />
    </CLASSES>
    <JAVADOC />
    <SOURCES />
  </library>
</orderEntry>
<orderEntry type="module-library" exported="">
  <library>
    <CLASSES>
      <root url="jar://$MODULE_DIR$/../mod1/lib/hamcrest-all-1.2.jar!/" />
    </CLASSES>
    <JAVADOC />
    <SOURCES />
  </library>
</orderEntry>

How can solve this problem? Path variables are not suitable in this case (or at least I don’t know how to use them to fix this problem with them).

Thank you for any help.