Skip to content

Commit

Permalink
Switch to cds-maven-plugin (#19)
Browse files Browse the repository at this point in the history
* use cds-maven-plugin

- added .cdsrc.json for cds build config
- removed cds, dependencies and scripts sections from package.json

* use cds-services in version 1.7.0

* version bump flatten-maven-plugin

* added a plugin feature section to README

* fixed wrong path to pom.xml

* minor edits

Co-authored-by: Iwona Hahn <iwonahahn@users.noreply.github.com>
  • Loading branch information
mofterdinger and iwonahahn committed Jul 7, 2020
1 parent 3f2231c commit ceb47b5
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 212 deletions.
20 changes: 20 additions & 0 deletions .cdsrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"build": {
"target": "."
},
"requires": {
"db": {
"kind": "sqlite",
"model": [
"db",
"srv"
],
"credentials": {
"database": "sqlite.db"
}
}
},
"odata": {
"version": "v4"
}
}
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ User Interface related Features:
- [Value Help](https://cap.cloud.sap/docs/cds/annotations#odata) for [Books](app/orders/fiori-service.cds) and [Authors](app/common.cds)
- [Model Localization](https://cap.cloud.sap/docs/guides/i18n) for [English](app/_i18n/i18n.properties) and [German](app/_i18n/i18n_de.properties) language for static texts

CDS Maven Plugin Features:

- Install [Node.js](srv/pom.xml#L87) in the specified version
- Install the latest version of [@sap/cds-dk](srv/pom.xml#L97)
- Execute arbitrary [CDS](srv/pom.xml#L107) commands
- [Generate](srv/pom.xml#L122) Java POJOs for type-safe access to the CDS model
- [Clean](srv/pom.xml#L80) project from artifacts of the previous build

# Getting Started

Expand Down
33 changes: 1 addition & 32 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,5 @@
"version": "1.0.0",
"description": "Bookshop using CAP Java NG",
"license": "Apache License Version 2.0",
"repository": "",
"scripts": {
"build": "cds build/all --clean",
"schema": "cds deploy --to sqlite --dry > srv/src/main/resources/schema.sql",
"deploy": "cds deploy"
},
"dependencies": {
"@sap/cds": "^3.33.0"
},
"devDependencies": {
"sqlite3": "^4.1.1"
},
"cds": {
"build": {
"target": "."
},
"requires": {
"db": {
"kind": "sqlite",
"model": [
"db",
"srv"
],
"credentials": {
"database": "sqlite.db"
}
}
},
"odata": {
"version": "v4"
}
}
"repository": "https://github.com/SAP-samples/cloud-cap-samples-java.git"
}
104 changes: 3 additions & 101 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@

<!-- DEPENDENCIES VERSION -->
<jdk.version>1.8</jdk.version>
<cds.services.version>1.6.0</cds.services.version>
<cds4j.version>1.10.0</cds4j.version>
<spring.boot.version>2.2.6.RELEASE</spring.boot.version>
<cds.services.version>1.7.0</cds.services.version>
<spring.boot.version>2.3.1.RELEASE</spring.boot.version>

<node.version>v12.16.2</node.version>
<node.url>https://nodejs.org/dist/</node.url>
</properties>

<modules>
Expand Down Expand Up @@ -51,102 +49,6 @@
</dependencyManagement>

<build>
<pluginManagement>
<plugins>
<!-- STEPS TO GENERATE CDS ARTIFACTS WITH AVAILABLE NODE/NPM -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>cds build</id>
<phase>initialize</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>npm</executable>
<arguments>
<argument>run</argument>
<argument>build</argument>
</arguments>
</configuration>
</execution>

<execution>
<id>cds schema</id>
<phase>initialize</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>npm</executable>
<arguments>
<argument>run</argument>
<argument>schema</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>

<!-- STEPS TO GENERATE CDS ARTIFACTS WITH EIRSLETT -->
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<id>install-node-and-npm</id>
<phase>initialize</phase>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<downloadRoot>${node.url}</downloadRoot>
<nodeVersion>${node.version}</nodeVersion>
<npmInheritsProxyConfigFromMaven>true</npmInheritsProxyConfigFromMaven>
</configuration>
</execution>

<execution>
<id>npm install</id>
<phase>initialize</phase>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>

<execution>
<id>cds build</id>
<phase>initialize</phase>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run build</arguments>
</configuration>
</execution>

<execution>
<id>cds schema</id>
<phase>initialize</phase>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run schema</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>

<plugins>
<!-- JAVA VERSION -->
<plugin>
Expand Down Expand Up @@ -174,7 +76,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.2.1</version>
<version>1.2.4</version>
<configuration>
<updatePomFile>true</updatePomFile>
<flattenMode>resolveCiFriendliesOnly</flattenMode>
Expand Down
128 changes: 49 additions & 79 deletions srv/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,108 +68,78 @@
</executions>
</plugin>

<!-- CONFIGURE ADDITIONAL SOURCE DIRECTORY FOR GENERATED CLASSES -->
<!-- STEPS TO BUILD CDS MODEL AND GENERATE POJOs -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<groupId>com.sap.cds</groupId>
<artifactId>cds-maven-plugin</artifactId>
<version>${cds.services.version}</version>
<configuration>
<nodeVersion>${node.version}</nodeVersion>
</configuration>
<executions>
<execution>
<phase>generate-sources</phase>
<id>cds.clean</id>
<goals>
<goal>add-source</goal>
<goal>clean</goal>
</goals>
</execution>

<execution>
<id>cds.install-node</id>
<goals>
<goal>install-node</goal>
</goals>
<configuration>
<sources>
<source>src/gen/java</source>
</sources>
<skip>${cdsdk-global}</skip>
</configuration>
</execution>

<execution>
<id>install-cdsdk</id>
<goals>
<goal>install-cdsdk</goal>
</goals>
<configuration>
<skip>${cdsdk-global}</skip>
</configuration>
</execution>
</executions>
</plugin>

<!-- GENERATE POJO INTERFACES -->
<plugin>
<groupId>com.sap.cds</groupId>
<artifactId>cds4j-maven-plugin</artifactId>
<version>${cds4j.version}</version>
<configuration>
<csnFile>${project.basedir}/src/main/resources/edmx/csn.json</csnFile>
<outputDirectory>${project.basedir}/src/gen</outputDirectory>
<basePackage>cds.gen</basePackage>
<eventContext>true</eventContext>
<excludes>
<exclude>localized.*</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>cds4j-generate-model</id>
<phase>generate-sources</phase>
<id>cds.build</id>
<goals>
<goal>cds</goal>
</goals>
<configuration>
<commands>
<command>build/all --clean</command>

<command>deploy --to sqlite --dry >
${project.basedir}/src/main/resources/schema.sql</command>
</commands>
</configuration>
</execution>

<execution>
<id>cds.generate</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<basePackage>cds.gen</basePackage>
</configuration>
</execution>
</executions>
</plugin>

<!-- CLEAN GENERATED ARTIFACTS -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<filesets>
<fileset>
<directory>src/gen</directory>
<followSymlinks>false</followSymlinks>
</fileset>
<fileset>
<directory>src/main/resources</directory>
<includes>
<include>edmx/**</include>
<include>schema.sql</include>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<!-- A profile that uses global installation of @sap/cds-dk -->
<profile>
<id>cdsdk-global</id>
<build>
<plugins>
<!-- STEPS TO GENERATE CDS ARTIFACTS IMPORTED FROM PARENT -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<workingDirectory>${project.basedir}/..</workingDirectory>
</configuration>
</plugin>
</plugins>
</build>
</profile>

<!-- The default profile that uses eirslett plugin to install and perform cds commands -->
<profile>
<id>cdsdk-local</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<!-- STEPS TO GENERATE CDS ARTIFACTS IMPORTED FROM PARENT -->
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<properties>
<cdsdk-global>true</cdsdk-global>
</properties>
</profile>
</profiles>
</project>

0 comments on commit ceb47b5

Please sign in to comment.