@@ -65,6 +65,136 @@ main =
65
65
>
66
66
> - Expand on the detail when there is time.
67
67
68
+ ## Download a Java Library from Maven Central
69
+
70
+ A typical use-case when bringing in some popular Java library into Enso
71
+ ecosystem is to download it (including is ** transitive dependencies** ) from
72
+ [ Maven Central] ( http://maven.org ) - a popular place hosting thousands of Java
73
+ libraries. Let's ** start from scratch** by creating an _ empty Enso project_ :
74
+
75
+ ``` bash
76
+ $ bin/enso --new polydemo
77
+ $ cd polydemo
78
+ polydemo$ find .
79
+ .
80
+ ./src
81
+ ./src/Main.enso
82
+ ./package.yaml
83
+ ```
84
+
85
+ To populate the appropriate ` polyglot/java ` subdirectory, let's create following
86
+ two files - ` pom.xml ` and ` assembly.xml ` and put them into root of the project,
87
+ next to ` package.yaml ` file. The content of ` assembly.xml ` is:
88
+
89
+ ``` xml
90
+ <?xml version =" 1.0" ?>
91
+ <assembly xmlns =" http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
92
+ xsi : schemaLocation =" http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd" >
93
+
94
+ <id >polyglot</id >
95
+ <formats >
96
+ <format >dir</format >
97
+ </formats >
98
+ <baseDirectory >/</baseDirectory >
99
+ <dependencySets >
100
+ <dependencySet >
101
+ <useProjectArtifact >false</useProjectArtifact >
102
+ <scope >runtime</scope >
103
+ <outputDirectory >/</outputDirectory >
104
+ <outputFileNameMapping >${artifact.artifactId}-${artifact.baseVersion}.${artifact.extension}</outputFileNameMapping >
105
+ </dependencySet >
106
+ </dependencySets >
107
+ </assembly >
108
+ ```
109
+
110
+ and let the content of the ` pom.xml ` be:
111
+
112
+ ``` xml
113
+ <?xml version =" 1.0" ?>
114
+ <project xmlns =" http://maven.apache.org/POM/4.0.0" xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
115
+ xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
116
+ <modelVersion >4.0.0</modelVersion >
117
+
118
+ <groupId >com.yourorg.yourproject</groupId >
119
+ <artifactId >download</artifactId >
120
+ <version >1.0-SNAPSHOT</version >
121
+ <packaging >jar</packaging >
122
+
123
+ <name >Download JARs for Your Project</name >
124
+ <build >
125
+ <plugins >
126
+ <plugin >
127
+ <artifactId >maven-assembly-plugin</artifactId >
128
+ <version >2.4</version >
129
+ <executions >
130
+ <execution >
131
+ <id >download</id >
132
+ <phase >package</phase >
133
+ <goals >
134
+ <goal >single</goal >
135
+ </goals >
136
+ <configuration >
137
+ <outputDirectory >polyglot</outputDirectory >
138
+ <appendAssemblyId >false</appendAssemblyId >
139
+ <finalName >java</finalName >
140
+ <descriptors >
141
+ <descriptor >assembly.xml</descriptor >
142
+ </descriptors >
143
+ </configuration >
144
+ </execution >
145
+ </executions >
146
+ </plugin >
147
+ </plugins >
148
+ </build >
149
+ <dependencies >
150
+ <dependency >
151
+ <!-- find your favorite Java library at maven.org
152
+ and put the co-ordinates here
153
+ -->
154
+ <groupId >com.google.analytics</groupId >
155
+ <artifactId >google-analytics-data</artifactId >
156
+ <version >0.44.0</version >
157
+ </dependency >
158
+ </dependencies >
159
+ </project >
160
+ ```
161
+
162
+ The files are instructing [ Maven] ( http://maven.apache.org ) - _ standard Java
163
+ build tool_ - to download
164
+ [ google-analytics-data library] ( https://central.sonatype.com/artifact/com.google.analytics/google-analytics-data/0.44.0 )
165
+ library version ` 0.44.0 ` and all _ its dependencies_ into your ` polyglot/java `
166
+ directory. Of course, _ feel free to find different library_ on
167
+ [ Maven central] ( http://maven.apache.org ) to download - edit ` pom.xml `
168
+ appropriately. Once your files are ready execute:
169
+
170
+ ``` bash
171
+ polydemo$ ls * ml
172
+ assembly.xml package.yaml pom.xml
173
+
174
+ polyglot$ mvn -q package
175
+
176
+ polydemo$ ls polyglot/java/* .jar
177
+ ...
178
+ ```
179
+
180
+ the [ mvn command] ( http://maven.apache.org ) invokes
181
+ [ Maven] ( http://maven.apache.org ) which in turns downloads all the requested
182
+ library JAR files (52 of them in the case of ` google-analytics-data ` ) into
183
+ ` polyglot/java ` directory. Now you are ready to use them.
184
+
185
+ There is a class ` com.google.analytics.data.v1alpha.AlphaAnalyticsDataClient `
186
+ among the downloaded libraries, as such let's modify ` src/Main.enso ` to:
187
+
188
+ ``` ruby
189
+ polyglot java import com.google.analytics.data.v1alpha.AlphaAnalyticsDataClient
190
+
191
+ main =
192
+ client = AlphaAnalyticsDataClient .create
193
+ client.close
194
+ ```
195
+
196
+ run the project and voilá, the Java classes are available to your Enso sources.
197
+
68
198
## Polyglot Syntax System
69
199
70
200
The static system, however, lets us do much better in terms of user experience.
0 commit comments