简体   繁体   中英

Adding eclipse project facet with gradle

I have aa gradle script that sets up an eclipse project for me. My project needs to have an extra project facet added in addition to the default ones. The documentation has the following example

eclipse {
  wtp {
    facet {
      //you can add some extra wtp facets; mandatory keys: 'name', 'version':
      facet name: 'someCoolFacet', version: '1.3'
    }
  }
}

I tried adding my own facet using the given example, but instead of the facet being added to the existing facets, it actually replaced all other facets thus being the only facet in the settings. Obviously, this is not what I intended. Question is, how do I add an extra facet to the default facets?

Edit:

I want to create a script that configures an eclipse project to a folder that only contains the project structure of an eclipse project, but no configuration files (.classpath, .project, .settings/). I'm trying to add Vaadin plugin for Eclipse facet to a Vaadin project. This is how my script looks like

subprojects {
    apply plugin: 'war'  
    apply plugin: 'eclipse-wtp'

    sourceCompatibility = 1.6  
    targetCompatibility = 1.6  
    webAppDirName = 'WebContent'  
    vaadinDir = webAppDirName+'/VAADIN'  

    eclipse {

        wtp {
            facet {         
              facet name: 'com.vaadin.integration.eclipse.core', version: '7.0'
            }
        }

    }

    // Source directories  
    sourceSets{  
        main{  
            java{  
                srcDir 'src'  
            }  
        }  
    }  


}

defaultTasks 'eclipse'

This is the resulting facet settings

<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
    <installed facet="com.vaadin.integration.eclipse.core" version="7.0"/>
</faceted-project>

Without defining any custom facets, the resulting configuration is

<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
    <fixed facet="jst.java"/>
    <fixed facet="jst.web"/>
    <installed facet="jst.web" version="2.4"/>
    <installed facet="jst.java" version="6.0"/>
</faceted-project>

As said, I'm all the facets to be in the settings :)

Modifying defaults (rather than overwriting them) can sometimes be tricky (it's not an easy problem for Gradle to solve), but you can try the following:

facet {
    facets = facets
    facet name: 'com.vaadin.integration.eclipse.core', version: '7.0'
}

Alternatively, you could declare the default facets explicitly, along with your custom facet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM