-
Notifications
You must be signed in to change notification settings - Fork 10
/
jvm_projects.html
1107 lines (1073 loc) · 69.4 KB
/
jvm_projects.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<!--
Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
Licensed under the Apache License, Version 2.0 (see LICENSE).
-->
<head>
<meta charset="utf-8"/>
<title>JVM Projects with Pants</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="pants-logo.ico">
<!-- In case this is a "test publish", tell search engines where real version lives: -->
<link rel="canonical" href="http://pantsbuild.org/jvm_projects.html">
<link rel="stylesheet" href="bootstrap-custom.min.css">
<link rel="stylesheet" href="bootstrap-custom-theme.min.css">
<link rel="stylesheet" href="docsite.css">
</head>
<body>
<div class="header">
<nav class="navbar navbar-default navbar-static-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand navbar-brand-img" href="index.html">
<img src="pants-logo.ico" alt="[pantsbuild logo]">
</a>
<a class="navbar-brand" href="index.html">
Pants v1
</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="/">Docs</a></li>
<li><a href="community.html">Community</a></li>
<li><a href="https://www.github.com/pantsbuild/pants">GitHub</a></li>
<li>
<form class="navbar-form navbar-left search" role="search" action="https://www.google.com/search">
<div class="form-group">
<input type="text" name="as_q" class="form-control query" placeholder="Search">
<input name="as_sitesearch" value="pantsbuild.org" type="hidden">
</div>
</form>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
<div class="deprecated">Pants v1 is no longer maintained. See <a href="https://www.pantsbuild.org/">here</a> for the Pants v2 documentation.</div>
</nav>
</div>
<div class="page">
<div class="container-fluid">
<div class="row">
<div class="col-md-1">
</div>
<div class="col-md-2">
<div class="site-toc">
<ul>
<li class="toc-h1 toc-heading">
Getting Started
</li>
<li class="toc-h1 toc-link ">
<a href="install.html">Installing Pants</a>
</li>
<li class="toc-h1 toc-link ">
<a href="setup_repo.html">Setting Up Pants</a>
</li>
<li class="toc-h1 toc-link ">
<a href="first_tutorial.html">Tutorial</a>
</li>
<li class="toc-h1 toc-link ">
<a href="common_tasks.html">Common Tasks</a>
</li>
<li class="toc-h1 toc-link ">
<a href="orgs.html">Pants for Organizations</a>
</li>
<li class="toc-h1 toc-heading">
Pants Basics
</li>
<li class="toc-h1 toc-link ">
<a href="why_use_pants.html">Why Use Pants?</a>
</li>
<li class="toc-h1 toc-link ">
<a href="first_concepts.html">Pants Concepts</a>
</li>
<li class="toc-h1 toc-link ">
<a href="build_files.html">BUILD files</a>
</li>
<li class="toc-h1 toc-link ">
<a href="target_addresses.html">Target Addresses</a>
</li>
<li class="toc-h1 toc-link ">
<a href="3rdparty.html">Third-Party Dependencies</a>
</li>
<li class="toc-h1 toc-link ">
<a href="options.html">Pants Options</a>
</li>
<li class="toc-h1 toc-link ">
<a href="invoking.html">Invoking Pants</a>
</li>
<li class="toc-h1 toc-link ">
<a href="reporting_server.html">Reporting Server</a>
</li>
<li class="toc-h1 toc-link ">
<a href="ide_support.html">IDE Support</a>
</li>
<li class="toc-h1">
<a class="sidebar-nav-heading" class="toc-drop" data-toggle="collapse" href="#JVM-Support" aria-expanded="false" aria-controls="JVM-Support">JVM Support<span class="caret"></span></a>
<ul class="" id="JVM-Support">
<li class="toc-h1 toc-link toc-here">
JVM Projects with Pants
</li>
<li class="toc-h1 toc-link ">
<a href="3rdparty_jvm.html">JVM Dependency Management</a>
</li>
<li class="toc-h1 toc-link ">
<a href="scala.html">Scala Support</a>
</li>
<li class="toc-h1 toc-link ">
<a href="publish.html">Publishing Artifacts</a>
</li>
<li class="toc-h1 toc-link ">
<a href="from_maven.html">Pants for Maven Experts</a>
</li>
</ul>
</li>
<li class="toc-h1">
<a class="sidebar-nav-heading" class="toc-drop" data-toggle="collapse" href="#Python-Support" aria-expanded="false" aria-controls="Python-Support">Python Support<span class="caret"></span></a>
<ul class="collapse sidebar-nav sidebar-submenu" id="Python-Support">
<li class="toc-h1 toc-link ">
<a href="python_readme.html">Python Projects with Pants</a>
</li>
<li class="toc-h1 toc-link ">
<a href="3rdparty_py.html">Python 3rdparty Pattern</a>
</li>
</ul>
</li>
<li class="toc-h1 toc-link ">
<a href="go_readme.html">Go support for Pants</a>
</li>
<li class="toc-h1 toc-link ">
<a href="node_readme.html">Node.js Support</a>
</li>
<li class="toc-h1 toc-heading">
Code & Doc Generation
</li>
<li class="toc-h1 toc-link ">
<a href="thrift_deps.html">Thrift</a>
</li>
<li class="toc-h1 toc-link ">
<a href="grpcio_gen.html">Python gRPC + protobufs</a>
</li>
<li class="toc-h1 toc-link ">
<a href="page.html">Markdown</a>
</li>
<li class="toc-h1 toc-heading">
Getting Help
</li>
<li class="toc-h1 toc-link ">
<a href="tshoot.html">Troubleshooting</a>
</li>
<li class="toc-h1 toc-link ">
<a href="community.html">Community</a>
</li>
<li class="toc-h1 toc-heading">
Reference
</li>
<li class="toc-h1 toc-link ">
<a href="build_dictionary.html">Pants BUILD Dictionary</a>
</li>
<li class="toc-h1 toc-link ">
<a href="options_reference.html">Pants Reference</a>
</li>
<li class="toc-h1">
<a class="sidebar-nav-heading" class="toc-drop" data-toggle="collapse" href="#Release-Notes" aria-expanded="false" aria-controls="Release-Notes">Release Notes<span class="caret"></span></a>
<ul class="collapse sidebar-nav sidebar-submenu" id="Release-Notes">
<li class="toc-h1 toc-link ">
<a href="notes-1.30.x.html">1.30.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.29.x.html">1.29.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.28.x.html">1.28.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.27.x.html">1.27.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.26.x.html">1.26.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.25.x.html">1.25.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.24.x.html">1.24.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.23.x.html">1.23.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.22.x.html">1.22.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.21.x.html">1.21.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.20.x.html">1.20.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.19.x.html">1.19.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.18.x.html">1.18.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.17.x.html">1.17.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.16.x.html">1.16.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.15.x.html">1.15.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.14.x.html">1.14.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.13.x.html">1.13.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.12.x.html">1.12.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.11.x.html">1.11.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.10.x.html">1.10.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.9.x.html">1.9.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.8.x.html">1.8.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.7.x.html">1.7.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.6.x.html">1.6.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.5.x.html">1.5.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.4.x.html">1.4.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.3.x.html">1.3.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.2.x.html">1.2.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.1.x.html">1.1.x Stable Releases</a>
</li>
<li class="toc-h1 toc-link ">
<a href="notes-1.0.x.html">1.0.x Stable Releases</a>
</li>
</ul>
</li>
<li class="toc-h1 toc-heading">
Developer
</li>
<li class="toc-h1 toc-link ">
<a href="dev.html">Pants Developer Center</a>
</li>
<li class="toc-h1 toc-link ">
<a href="export.html">Export Format</a>
</li>
<li class="toc-h1 toc-link ">
<a href="architecture.html">Architecture</a>
</li>
<li class="toc-h1 toc-heading">
Blogs
</li>
<li class="toc-h1 toc-link ">
<a href="coursier_migration.html">Twitter's Coursier Migration</a>
</li>
</ul>
</div> <!-- site-toc -->
</div>
<div class="col-md-8">
<div class="content">
<div class="mainflow">
<nav class="pagetoc">
<ul>
<li class="toc-h1"><a href="#relevant-goals-and-targets">Relevant Goals and Targets</a></li>
<li class="toc-h1"><a href="#build-for-a-simple-binary">BUILD for a Simple Binary</a></li>
<li class="toc-h2"><a href="#depending-on-a-library">Depending on a Library</a></li>
<li class="toc-h2"><a href="#a-test-target">A Test Target</a></li>
<li class="toc-h2"><a href="#depending-on-a-jar">Depending on a Jar</a></li>
<li class="toc-h1"><a href="#the-usual-commands-jvm">The Usual Commands: JVM</a></li>
<li class="toc-h1"><a href="#toolchain">Toolchain</a></li>
<li class="toc-h2"><a href="#ivy">Ivy</a></li>
<li class="toc-h2"><a href="#coursier">Coursier</a></li>
<li class="toc-h3"><a href="#limitation">Limitation</a></li>
<li class="toc-h3"><a href="#example-config-to-use-coursier">Example config to use coursier</a></li>
<li class="toc-h4"><a href="#for-pants-17x">For Pants >= 1.7.x</a></li>
<li class="toc-h4"><a href="#for-pants-16x">For Pants <= 1.6.x</a></li>
<li class="toc-h2"><a href="#nailgun">Nailgun</a></li>
<li class="toc-h2"><a href="#zinc">Zinc</a></li>
<li class="toc-h1"><a href="#java9-vs-java8-which-java">Java9 vs Java8, Which Java</a></li>
<li class="toc-h1"><a href="#bundles-deploy-able-runnable-file-trees">Bundles: Deploy-able Runnable File Trees</a></li>
<li class="toc-h2"><a href="#generating-a-bundle">Generating a Bundle</a></li>
<li class="toc-h2"><a href="#contents-of-a-bundle">Contents of a Bundle</a></li>
<li class="toc-h2"><a href="#deploying-a-bundle">Deploying a Bundle</a></li>
<li class="toc-h1"><a href="#omitting-or-shading-the-contents-of-a-binary">Omitting or Shading the Contents of a Binary</a></li>
<li class="toc-h2"><a href="#omitting">Omitting</a></li>
<li class="toc-h2"><a href="#shading">Shading</a></li>
<li class="toc-h1"><a href="#target-scopes">Target Scopes</a></li>
<li class="toc-h2"><a href="#overview">Overview</a></li>
<li class="toc-h2"><a href="#correspondence-with-other-build-systems">Correspondence with other build systems</a></li>
<li class="toc-h2"><a href="#scope-values">Scope values</a></li>
<li class="toc-h2"><a href="#setting-target-scopes">Setting target scopes</a></li>
<li class="toc-h1"><a href="#dependency-hygiene">Dependency Hygiene</a></li>
<li class="toc-h2"><a href="#for-local-analysis">For local analysis</a></li>
<li class="toc-h2"><a href="#for-global-analysis">For global analysis</a></li>
<li class="toc-h1"><a href="#compiler-plugins">Compiler Plugins</a></li>
<li class="toc-h1"><a href="#further-reading">Further Reading</a></li>
</ul>
</nav>
<!-- main content start -->
<!-- generated by pants! -->
<style>
.codehilite .hll { background-color: #ffffcc }
.codehilite { background: #f0f0f0; }
.codehilite .c { color: #60a0b0; font-style: italic } /* Comment */
.codehilite .err { border: 1px solid #FF0000 } /* Error */
.codehilite .k { color: #007020; font-weight: bold } /* Keyword */
.codehilite .o { color: #666666 } /* Operator */
.codehilite .ch { color: #60a0b0; font-style: italic } /* Comment.Hashbang */
.codehilite .cm { color: #60a0b0; font-style: italic } /* Comment.Multiline */
.codehilite .cp { color: #007020 } /* Comment.Preproc */
.codehilite .cpf { color: #60a0b0; font-style: italic } /* Comment.PreprocFile */
.codehilite .c1 { color: #60a0b0; font-style: italic } /* Comment.Single */
.codehilite .cs { color: #60a0b0; background-color: #fff0f0 } /* Comment.Special */
.codehilite .gd { color: #A00000 } /* Generic.Deleted */
.codehilite .ge { font-style: italic } /* Generic.Emph */
.codehilite .gr { color: #FF0000 } /* Generic.Error */
.codehilite .gh { color: #000080; font-weight: bold } /* Generic.Heading */
.codehilite .gi { color: #00A000 } /* Generic.Inserted */
.codehilite .go { color: #888888 } /* Generic.Output */
.codehilite .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */
.codehilite .gs { font-weight: bold } /* Generic.Strong */
.codehilite .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
.codehilite .gt { color: #0044DD } /* Generic.Traceback */
.codehilite .kc { color: #007020; font-weight: bold } /* Keyword.Constant */
.codehilite .kd { color: #007020; font-weight: bold } /* Keyword.Declaration */
.codehilite .kn { color: #007020; font-weight: bold } /* Keyword.Namespace */
.codehilite .kp { color: #007020 } /* Keyword.Pseudo */
.codehilite .kr { color: #007020; font-weight: bold } /* Keyword.Reserved */
.codehilite .kt { color: #902000 } /* Keyword.Type */
.codehilite .m { color: #40a070 } /* Literal.Number */
.codehilite .s { color: #4070a0 } /* Literal.String */
.codehilite .na { color: #4070a0 } /* Name.Attribute */
.codehilite .nb { color: #007020 } /* Name.Builtin */
.codehilite .nc { color: #0e84b5; font-weight: bold } /* Name.Class */
.codehilite .no { color: #60add5 } /* Name.Constant */
.codehilite .nd { color: #555555; font-weight: bold } /* Name.Decorator */
.codehilite .ni { color: #d55537; font-weight: bold } /* Name.Entity */
.codehilite .ne { color: #007020 } /* Name.Exception */
.codehilite .nf { color: #06287e } /* Name.Function */
.codehilite .nl { color: #002070; font-weight: bold } /* Name.Label */
.codehilite .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */
.codehilite .nt { color: #062873; font-weight: bold } /* Name.Tag */
.codehilite .nv { color: #bb60d5 } /* Name.Variable */
.codehilite .ow { color: #007020; font-weight: bold } /* Operator.Word */
.codehilite .w { color: #bbbbbb } /* Text.Whitespace */
.codehilite .mb { color: #40a070 } /* Literal.Number.Bin */
.codehilite .mf { color: #40a070 } /* Literal.Number.Float */
.codehilite .mh { color: #40a070 } /* Literal.Number.Hex */
.codehilite .mi { color: #40a070 } /* Literal.Number.Integer */
.codehilite .mo { color: #40a070 } /* Literal.Number.Oct */
.codehilite .sa { color: #4070a0 } /* Literal.String.Affix */
.codehilite .sb { color: #4070a0 } /* Literal.String.Backtick */
.codehilite .sc { color: #4070a0 } /* Literal.String.Char */
.codehilite .dl { color: #4070a0 } /* Literal.String.Delimiter */
.codehilite .sd { color: #4070a0; font-style: italic } /* Literal.String.Doc */
.codehilite .s2 { color: #4070a0 } /* Literal.String.Double */
.codehilite .se { color: #4070a0; font-weight: bold } /* Literal.String.Escape */
.codehilite .sh { color: #4070a0 } /* Literal.String.Heredoc */
.codehilite .si { color: #70a0d0; font-style: italic } /* Literal.String.Interpol */
.codehilite .sx { color: #c65d09 } /* Literal.String.Other */
.codehilite .sr { color: #235388 } /* Literal.String.Regex */
.codehilite .s1 { color: #4070a0 } /* Literal.String.Single */
.codehilite .ss { color: #517918 } /* Literal.String.Symbol */
.codehilite .bp { color: #007020 } /* Name.Builtin.Pseudo */
.codehilite .fm { color: #06287e } /* Name.Function.Magic */
.codehilite .vc { color: #bb60d5 } /* Name.Variable.Class */
.codehilite .vg { color: #bb60d5 } /* Name.Variable.Global */
.codehilite .vi { color: #bb60d5 } /* Name.Variable.Instance */
.codehilite .vm { color: #bb60d5 } /* Name.Variable.Magic */
.codehilite .il { color: #40a070 } /* Literal.Number.Integer.Long */
</style>
<h1 id="jvm-projects-with-pants">JVM Projects with Pants</h1>
<p>Assuming you know the basic
<a href="first_concepts.html">Pants concepts</a>
and have gone through the
<a href="first_tutorial.html">first Tutorial</a>,
you've made a great start towards
using Pants to work with Java and Scala code. This page goes into some
of the details.</p>
<p>If you are accustomed to the Maven tool and contemplating moving to
Pants, you are not alone;
<a href="from_maven.html">Pants for Maven Experts</a>
has some advice.</p>
<h2 id="relevant-goals-and-targets">Relevant Goals and Targets</h2>
<p>When working with JVM languages, the following goals and targets are
especially relevant.</p>
<p><strong>Deployable Bundle</strong> <em>Runnable Binary, optionally with non-JVM files</em></p>
<blockquote>
<p>Deployable bundles are directories, optionally archived, that contain
all files necessary to run the application. The <code>bundle</code> goal is used
to create these deployable bundles from either <code>jvm_binary</code> or
<code>jvm_app</code> targets.</p>
<p>Bundling a <code>jvm_binary</code> target is appropriate when your application is
entirely jar-based; that is, it's entirely class files and resources
packaged inside the jars themselves. If your application requires
"extra stuff" (e.g.: start scripts, config files) use a <code>jvm_app</code>
which allows you to include files in the bundle directory that
supplement the binary jar and its dependencies. You can learn
more about <a href="jvm_projects.html#jvm_bundles" pantsref="jvm_bundles">bundles</a>.</p>
</blockquote>
<p><strong>Runnable Binary</strong></p>
<blockquote>
<p>On its own, a <code>jvm_binary</code> BUILD target describes an executable <code>.jar</code>
(something you can run with <code>java -jar</code>). The jar is described as
executable because it contains a manifest file that specifies the main
class as well as classpath for all dependencies. If your program
contains only jars (and resources packaged in those jars), this is all
you need to run the binary. Use <code>./pants binary</code> to compile its
code; <code>./pants run</code> to run it "in place".</p>
</blockquote>
<p><strong>Importable Code</strong></p>
<blockquote>
<p><code>java_library</code> BUILD targets make Java source code <code>import</code>-able. The
rule of thumb is that each directory of <code>.java</code> files has a <code>BUILD</code>
file with a <code>java_library</code> target. A JVM target that has a
<code>java_library</code> in its <code>dependencies</code> can import its code.
<code>scala_library</code> targets are similar, but compiled with Scala.</p>
<p>To use pre-built <code>.jar</code>s, a JVM target can depend on a <code>jar</code>, a
reference to published code; these <code>jar</code>s normally live in a
directory called
<a href="3rdparty_jvm.html">3rdparty</a>.</p>
<p>Pants can <code>publish</code> a JVM library so code in other repos can use it;
if the <code>*_library</code> target has a <code>provides</code> parameter, that specifies
the repo/address at which to <a href="publish.html">publish</a>.</p>
<p>An <code>annotation_processor</code> BUILD target defines a Java library one
containing one or more annotation processors.</p>
</blockquote>
<p><strong>Tests</strong></p>
<blockquote>
<p>A <code>junit_tests</code> BUILD target holds source code for some JUnit tests;
typically, it would have one or more <code>java_library</code> targets as
dependencies and would import and test their code.</p>
<p>Pants also includes support for using the ScalaTest framework. The
testing framework automatically picks up scala tests that extend the
org.scalatest.Suite class and runs them
using org.scalatestplus.junit.JUnitRunner.</p>
<p>Most other scala test frameworks support running with JUnit via a base
class/trait or via a <code>@RunWith</code> annotation; so you can use
<code>junit_tests</code> for your scala tests as well.</p>
<p>The Pants <code>test</code> goal runs tests.</p>
</blockquote>
<p><strong>Generated Code</strong></p>
<blockquote>
<p>A <code>java_thrift_library</code> generates Java code from <code>.thrift</code> source; a
JVM target that has this target in its <code>dependencies</code> can <code>import</code> the
generated Java code. A <code>java_protobuf_library</code> is similar, but
generates Java code from protobuffer source.</p>
</blockquote>
<h2 id="build-for-a-simple-binary">BUILD for a Simple Binary</h2>
<p>The <a href="https://github.com/pantsbuild/pants/tree/master/examples/src/java/org/pantsbuild/example/hello">Pants Build Java hello world
sample</a>
code shows the BUILD file for a simple Java binary (in the <code>main/</code>
directory):</p>
<p>
<div class="md-included-snippet"><div class="codehilite"><pre><span></span><span class="n">jvm_binary</span><span class="p">(</span><span class="n">name</span> <span class="o">=</span> <span class="s1">'main-bin'</span><span class="p">,</span>
<span class="n">dependencies</span> <span class="o">=</span> <span class="p">[</span>
<span class="s1">'examples/src/java/org/pantsbuild/example/hello/greet'</span><span class="p">,</span>
<span class="s1">'examples/src/resources/org/pantsbuild/example/hello'</span><span class="p">,</span>
<span class="p">],</span>
<span class="n">sources</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'HelloMain.java'</span><span class="p">],</span>
<span class="n">main</span> <span class="o">=</span> <span class="s1">'org.pantsbuild.example.hello.main.HelloMain'</span><span class="p">,</span>
<span class="n">basename</span> <span class="o">=</span> <span class="s1">'hello-example'</span><span class="p">,</span>
<span class="p">)</span>
</pre></div>
</div>
</p>
<p>This small program has just one dependency. It is a library, a <code>java_library</code>, a compiled set of
source code from this workspace.</p>
<h3 id="depending-on-a-library">Depending on a Library</h3>
<p>The rule of thumb is that each directory of <code>.java</code> or <code>.scala</code> files
has a library target. If you find yourself thinking "we should move some
of this code to another directory," you probably also want to set up a
<code>BUILD</code> file with a <code>java_library</code> (or <code>scala_library</code>) target. Here we
see the library target which <code>main-bin</code> depends on. This library target
lives in <code>hello/greet/BUILD</code>:</p>
<p>
<div class="md-included-snippet"><div class="codehilite"><pre><span></span><span class="c1"># Note that the target has no explicit name, so it defaults to the name</span>
<span class="c1"># of the directory, in this case 'greet'.</span>
<span class="c1"># It also has no explicit sources, so it defaults to the sources implied</span>
<span class="c1"># by the target type, in this case "['*.java']".</span>
<span class="n">java_library</span><span class="p">(</span>
<span class="n">dependencies</span> <span class="o">=</span> <span class="p">[],</span> <span class="c1"># A more realistic example would depend on other libs,</span>
<span class="c1"># but this "hello world" is pretty simple.</span>
<span class="n">provides</span> <span class="o">=</span> <span class="n">artifact</span><span class="p">(</span><span class="n">org</span><span class="o">=</span><span class="s1">'org.pantsbuild.example'</span><span class="p">,</span>
<span class="n">name</span><span class="o">=</span><span class="s1">'hello-greet'</span><span class="p">,</span>
<span class="n">repo</span><span class="o">=</span><span class="n">public</span><span class="p">,),</span>
<span class="p">)</span>
</pre></div>
</div>
</p>
<p>This library could depend on other build targets and artifacts; if your
code imports something, that implies a <code>BUILD</code> dependency.</p>
<h3 id="a-test-target">A Test Target</h3>
<p>The <a href="https://github.com/pantsbuild/pants/tree/master/examples/tests/java/org/pantsbuild/example/hello">Pants Java Hello World example
tests</a>
are normal JUnit tests. To run them with Pants, we need a target for
them:</p>
<p>
<div class="md-included-snippet"><div class="codehilite"><pre><span></span><span class="n">junit_tests</span><span class="p">(</span>
<span class="n">dependencies</span><span class="o">=</span><span class="p">[</span>
<span class="s1">'examples/src/java/org/pantsbuild/example/hello/greet'</span><span class="p">,</span>
<span class="s1">'examples/src/resources/org/pantsbuild/example/hello'</span><span class="p">,</span>
<span class="p">],</span>
<span class="p">)</span>
</pre></div>
</div>
</p>
<p>As with other targets, this one depends on code that it imports. Thus, a typical test target
depends the library that it tests and perhaps some others (here, <code>junit</code>).
The dependency on <code>junit</code> is a "third party" dependency, a pre-compiled artifact whose source
lives somewhere outside the workspace.</p>
<h3 id="depending-on-a-jar">Depending on a Jar</h3>
<p>The test example depends on a jar, <code>junit</code>. Instead of compiling from
source, Pants invokes the resolver to fetch such jars. To reduce the danger of
version conflicts, we use the 3rdparty idiom: we keep references to
these "third-party" jars together in <code>BUILD</code> files under the <code>3rdparty/</code>
directory. Thus, the test has a <code>3rdparty</code> dependency:</p>
<p>
<div class="md-included-snippet"><div class="codehilite"><pre><span></span><span class="n">junit_tests</span><span class="p">(</span>
<span class="n">dependencies</span><span class="o">=</span><span class="p">[</span>
<span class="s1">'examples/src/java/org/pantsbuild/example/hello/greet'</span><span class="p">,</span>
<span class="s1">'examples/src/resources/org/pantsbuild/example/hello'</span><span class="p">,</span>
<span class="p">],</span>
<span class="p">)</span>
</pre></div>
</div>
</p>
<p>The <code>BUILD</code> files in <code>3rdparty/</code> have targets like:</p>
<div class="codehilite"><pre><span></span><span class="n">jar_library</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">'junit'</span><span class="p">,</span>
<span class="n">jars</span> <span class="o">=</span> <span class="p">[</span>
<span class="n">jar</span><span class="p">(</span><span class="n">org</span><span class="o">=</span><span class="s1">'junit'</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s1">'junit-dep'</span><span class="p">,</span> <span class="n">rev</span><span class="o">=</span><span class="s1">'4.11'</span><span class="p">)</span><span class="o">.</span><span class="n">with_sources</span><span class="p">(),</span>
<span class="p">],</span>
<span class="n">dependencies</span> <span class="o">=</span> <span class="p">[</span>
<span class="s1">':hamcrest-core'</span><span class="p">,</span>
<span class="p">],</span>
<span class="p">)</span>
</pre></div>
<p>Those <a href="build_dictionary.html#bdict_jar" pantsref="bdict_jar"><code>jar()</code> things</a> are references to public jars.
You can read more about
<a href="3rdparty_jvm.html">JVM 3rdparty dependencies</a>.</p>
<h2 id="the-usual-commands-jvm">The Usual Commands: JVM</h2>
<p><strong>Make sure code compiles and tests pass:</strong></p>
<p>Use the <code>test</code> goal with the targets you're interested in. If they are test targets,
Pants runs the tests. If they aren't test targets, Pants still compiles them since it knows it
must compile before it can test.</p>
<div class="codehilite"><pre><span></span>$ ./pants <span class="nb">test</span> examples/src/java/org/pantsbuild/example/hello/:: examples/tests/java/org/pantsbuild/example/hello/::
</pre></div>
<p>Assuming you use <code>junit_test</code> targets, output from the <code>junit</code> run is written to
<code>.pants.d/test/junit/</code>; you can see it on the console with <code>--output-mode=ALL</code>:</p>
<div class="codehilite"><pre><span></span>$ ./pants test.junit --output-mode<span class="o">=</span>ALL examples/tests/java/org/pantsbuild/example/hello::
</pre></div>
<p><strong>Run just that one troublesome test class:</strong> (assuming a JUnit test;
other frameworks use other flags)</p>
<div class="codehilite"><pre><span></span>$ ./pants test.junit --test<span class="o">=</span>org.pantsbuild.example.hello.greet.GreetingTest examples/tests/java/org/pantsbuild/example/hello/::
</pre></div>
<p><strong>Packaging Binaries</strong></p>
<p>To create a <a href="jvm_projects.html#jvm_bundles" pantsref="jvm_bundles">bundle</a> (a binary and its dependencies, perhaps
including helper files):</p>
<div class="codehilite"><pre><span></span>$ ./pants bundle --bundle-jvm-archive<span class="o">=</span>zip examples/src/java/org/pantsbuild/example/hello/main
...lots of build output...
<span class="m">08</span>:50:54 <span class="m">00</span>:02 <span class="o">[</span>create-monolithic-jar<span class="o">]</span>
<span class="m">08</span>:50:54 <span class="m">00</span>:02 <span class="o">[</span>add-internal-classes<span class="o">]</span>
<span class="m">08</span>:50:54 <span class="m">00</span>:02 <span class="o">[</span>jar-tool<span class="o">]</span>
created dist/hello-example.zip
<span class="m">08</span>:50:54 <span class="m">00</span>:02 <span class="o">[</span>dup<span class="o">]</span>
<span class="m">08</span>:50:54 <span class="m">00</span>:02 <span class="o">[</span>apk<span class="o">]</span>
<span class="m">08</span>:50:54 <span class="m">00</span>:02 <span class="o">[</span>apk-bundle<span class="o">]</span>
SUCCESS
$
</pre></div>
<p>This generates a zipfile with runnable contents; instead of a zipfile, we could have put the
contents a directory tree, a giant jar, or something else.
<a href="jvm_projects.html#jvm_bundles" pantsref="jvm_bundles">Learn more about bundles</a>.</p>
<h2 id="toolchain">Toolchain</h2>
<h3 id="ivy">Ivy</h3>
<p>Pants uses <a href="http://ant.apache.org/ivy/">Ivy</a> to resolve <code>jar</code> dependencies. To change how Pants
resolves these, configure <code>resolve.ivy</code>.</p>
<h3 id="coursier">Coursier</h3>
<p>Starting at release <code>1.4.0.dev26</code>, Pants added an option to pick <a href="https://github.com/coursier/coursier">coursier</a>
as the JVM 3rdparty resolver, with performance improvement being the main motivation. The goal is to retire ivy
eventually.</p>
<h4 id="limitation">Limitation</h4>
<ul>
<li>Currently coursier only supports maven style repo resolves. <a href="https://github.com/coursier/coursier/issues/created_by/benjyw">Resolving with ivy settings is still not mature</a>.</li>
<li>Coursier does not do publishing.</li>
</ul>
<h4 id="example-config-to-use-coursier">Example config to use coursier</h4>
<h5 id="for-pants-17x">For Pants >= 1.7.x</h5>
<div class="codehilite"><pre><span></span><span class="c1"># This will turn on coursier and turn off ivy.</span>
<span class="k">[resolver]</span>
<span class="n">resolver</span> <span class="o">=</span> <span class="s">"coursier"</span>
<span class="k">[resolve.coursier]</span>
<span class="c1"># jvm option in case of large resolves</span>
<span class="n">jvm_options</span> <span class="o">=</span> <span class="k">['-Xmx4g', '-XX:MaxMetaspaceSize=256m']</span>
<span class="k">[export]</span>
<span class="c1"># Same if needed for large resolves</span>
<span class="n">jvm_options</span> <span class="o">=</span> <span class="k">['-Xmx4g', '-XX:MaxMetaspaceSize=256m']</span>
<span class="k">[coursier]</span>
<span class="n">repos</span> <span class="o">=</span> <span class="k">['https://repo1.maven.org/maven2', 'https://dl.google.com/dl/android/maven2/']</span>
<span class="c1"># Change the following if you choose to [build coursier jar from scratch](https://github.com/coursier/coursier/blob/master/DEVELOPMENT.md#build-with-pants)</span>
<span class="c1"># or to fetch from different location.</span>
<span class="n">bootstrap_jar_url</span> <span class="o">=</span> <span class="s">"<url>"</span>
<span class="n">version</span> <span class="o">=</span> <span class="s">"<version>"</span>
</pre></div>
<ul>
<li>To inspect the resolve result, specify <code>--resolver-coursier-report</code></li>
<li>To show coursier command line invocation, use <code>-ldebug</code><div class="codehilite"><pre><span></span>./pants --resolver-resolver<span class="o">=</span>coursier resolve.coursier --report examples/tests/scala/org/pantsbuild/example/hello/welcome -ldebug
</pre></div>
</li>
</ul>
<h5 id="for-pants-16x">For Pants <= 1.6.x</h5>
<p>Note that this uses <code>pants.ini</code> rather than <code>pants.toml</code>.</p>
<div class="codehilite"><pre><span></span><span class="c1"># This will turn on coursier and turn off ivy.</span>
<span class="k">[resolver]</span>
<span class="na">resolver: coursier</span>
<span class="k">[export]</span>
<span class="c1"># Same if needed for large resolves</span>
<span class="na">jvm_options: ['-Xmx4g', '-XX:MaxMetaspaceSize</span><span class="o">=</span><span class="s">256m']</span>
<span class="k">[coursier]</span>
<span class="c1"># Change the following if you choose to [build coursier jar from scratch](https://github.com/coursier/coursier/blob/master/DEVELOPMENT.md#build-with-pants)</span>
<span class="c1"># or to fetch from different location.</span>
<span class="na">bootstrap_jar_url: <url></span>
<span class="na">version: <version></span>
<span class="na">fetch_options: [</span>
<span class="c1"># Specify maven repos</span>
<span class="na">'-r', 'https://repo1.maven.org/maven2/',</span>
<span class="na">'-r', 'https://dl.google.com/dl/android/maven2/',</span>
<span class="c1"># Quiet mode</span>
<span class="na">'-q',</span>
<span class="c1"># Do not use default public maven repo.</span>
<span class="na">'--no-default',</span>
<span class="c1"># Concurrent workers</span>
<span class="na">'-n', '10',</span>
<span class="c1"># Specify the type of artifacts to fetch</span>
<span class="na">'-A', 'jar,bundle,test-jar,maven-plugin,src,doc,aar'</span>
<span class="na">]</span>
</pre></div>
<h3 id="nailgun">Nailgun</h3>
<p>Pants uses <a href="https://github.com/martylamb/nailgun">Nailgun</a> to speed up compiles. Nailgun is a
JVM daemon that runs in the background. This means you don't need to start up a JVM and load
classes for each JVM-based operation. Things go faster.</p>
<h3 id="zinc">Zinc</h3>
<p>Pants uses Zinc, a dependency tracking compiler facade that supports sub-target incremental
compilation for Java and Scala.</p>
<h2 id="java9-vs-java8-which-java">Java9 vs Java8, Which Java</h2>
<p>Pants first looks through any JDKs specified by the <code>paths</code> map in pants.toml's jvm-distributions
section, eg:</p>
<div class="codehilite"><pre><span></span><span class="k">[jvm-distributions]</span>
<span class="n">paths</span> <span class="o">=</span> <span class="s">"""</span>
<span class="s">{</span>
<span class="s"> 'macos': [</span>
<span class="s"> '/Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk',</span>
<span class="s"> '/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk',</span>
<span class="s"> ],</span>
<span class="s"> 'linux': [</span>
<span class="s"> '/usr/java/jdk1.8.0_152',</span>
<span class="s"> ]</span>
<span class="s">}</span>
<span class="s">"""</span>
</pre></div>
<p>If no JVMs are found there, Pants uses the first Java it finds in <code>JDK_HOME</code>, <code>JAVA_HOME</code>,
or <code>PATH</code>. If no <code>paths</code> are specified in pants.toml, you can use JDK_HOME to set the Java version
for just one pants invocation:</p>
<div class="codehilite"><pre><span></span>$ <span class="nv">JDK_HOME</span><span class="o">=</span>/usr/lib/jvm/java-1.8.0-openjdk-amd64 ./pants ...
</pre></div>
<p>If you sometimes need to compile some code in Java 8 and sometimes Java 9, you can define
jvm-platforms in pants.toml, and set what targets use which platforms. For example, in pants.toml:</p>
<div class="codehilite"><pre><span></span><span class="k">[jvm-platform]</span>
<span class="n">default_platform</span> <span class="o">=</span> <span class="s">"java8"</span>
<span class="n">platforms</span> <span class="o">=</span> <span class="s">"""</span>
<span class="s">{</span>
<span class="s"> 'java8': {'source': '8', 'target': '8', 'args': [] },</span>
<span class="s"> 'java9': {'source': '9', 'target': '9', 'args': [] },</span>
<span class="s">}</span>
<span class="s">"""</span>
</pre></div>
<p>And then in a BUILD file:</p>
<div class="codehilite"><pre><span></span><span class="n">java_library</span><span class="p">(</span>
<span class="n">name</span><span class="o">=</span><span class="s1">'my-library'</span><span class="p">,</span>
<span class="n">sources</span><span class="o">=</span><span class="p">[</span><span class="s1">'*.java'</span><span class="p">],</span>
<span class="n">platform</span><span class="o">=</span><span class="s1">'java9'</span><span class="p">,</span>
<span class="p">)</span>
</pre></div>
<p>You can also override these on the cli:</p>
<div class="codehilite"><pre><span></span>./pants compile --jvm-platform-default-platform<span class="o">=</span>java9 examples/src/java/org/pantsbuild/example/hello/main
</pre></div>
<p>If you want to set the <code>-bootclasspath</code> (or <code>-Xbootclasspath</code>) to use the
appropriate java distribution, you can use the <code>$JAVA_HOME</code> symbol in the
<code>args</code> list. For example:</p>
<div class="codehilite"><pre><span></span><span class="k">[jvm-platform]</span>
<span class="n">default_platform</span> <span class="o">=</span> <span class="s">"java8"</span>
<span class="n">platforms</span> <span class="o">=</span> <span class="s">"""</span>
<span class="s">{</span>
<span class="s"> 'java8': {'source': '8', 'target': '8', 'args': ["</span><span class="err">-</span><span class="n">C-bootclasspath</span><span class="p">:</span><span class="err">$</span><span class="n">JAVA_HOME</span><span class="err">/</span><span class="n">jre</span><span class="err">/</span><span class="n">lib</span><span class="err">/</span><span class="n">resources</span><span class="p">.</span><span class="n">jar</span><span class="p">:</span><span class="err">$</span><span class="n">JAVA_HOME</span><span class="err">/</span><span class="n">jre</span><span class="err">/</span><span class="n">lib</span><span class="err">/</span><span class="n">rt</span><span class="p">.</span><span class="n">jar</span><span class="p">:</span><span class="err">$</span><span class="n">JAVA_HOME</span><span class="err">/</span><span class="n">jre</span><span class="err">/</span><span class="n">lib</span><span class="err">/</span><span class="n">sunrsasign</span><span class="p">.</span><span class="n">jar</span><span class="p">:</span><span class="err">$</span><span class="n">JAVA_HOME</span><span class="err">/</span><span class="n">jre</span><span class="err">/</span><span class="n">lib</span><span class="err">/</span><span class="n">jsse</span><span class="p">.</span><span class="n">jar</span><span class="p">:</span><span class="err">$</span><span class="n">JAVA_HOME</span><span class="err">/</span><span class="n">jre</span><span class="err">/</span><span class="n">lib</span><span class="err">/</span><span class="n">jce</span><span class="p">.</span><span class="n">jar</span><span class="p">:</span><span class="err">$</span><span class="n">JAVA_HOME</span><span class="err">/</span><span class="n">jre</span><span class="err">/</span><span class="n">lib</span><span class="err">/</span><span class="n">charsets</span><span class="p">.</span><span class="n">jar</span><span class="p">:</span><span class="err">$</span><span class="n">JAVA_HOME</span><span class="err">/</span><span class="n">jre</span><span class="err">/</span><span class="n">lib</span><span class="err">/</span><span class="n">jfr</span><span class="p">.</span><span class="n">jar</span><span class="p">:</span><span class="err">$</span><span class="n">JAVA_HOME</span><span class="err">/</span><span class="n">jre</span><span class="err">/</span><span class="n">classes</span><span class="err">"</span><span class="p">]</span> <span class="p">},</span>
<span class="p">}</span>
</pre></div>
<p>Your <code>-bootclasspath</code> should be designed to work with any compatible version of
the JVM that might be used. If you make use of <code>[jvm-distributions]</code> and have
strict control over what jvm installations are used by developers, this means you
probably only have to make it work for one version of the JDK. Otherwise, you
should design your bootclasspath to reference the union of all possible jars
you might need to pull in from different JVMs (any paths that aren't available
will simply be ignored by java).</p>
<p><strong>Note:</strong> Currently, pants is known to work with OpenJDK and Oracle JDK version 8 or greater.</p>
<p><a id="jvm_bundles" pantsmark="jvm_bundles"></a></p>
<h2 id="bundles-deploy-able-runnable-file-trees">Bundles: Deploy-able Runnable File Trees</h2>
<p>You can enjoy your web service on your development machine's
<code>localhost</code>, but to let other people enjoy it, you probably want to copy
it to a server machine. With Pants, the easiest way to do this is to
create a <em>bundle</em>: a directory tree of <code>.jar</code> and helper files.</p>
<p>Our "hello world" sample application needs a configuration file to run
correctly. (You can try to run without the configuration file, but the
program crashes immediately.) We define a <code>jvm_app</code> that represents a
runnable binary and "bundles" of extra files:</p>
<p>
<div class="md-included-snippet"><div class="codehilite"><pre><span></span><span class="c1"># Note that the target has no explicit name, so it defaults to the name</span>
<span class="c1"># of the directory, in this case 'main'.</span>
<span class="n">jvm_app</span><span class="p">(</span>
<span class="n">basename</span> <span class="o">=</span> <span class="s1">'hello-example'</span><span class="p">,</span>
<span class="n">dependencies</span> <span class="o">=</span> <span class="p">[</span>
<span class="s1">':main-bin'</span>
<span class="p">],</span>
<span class="n">bundles</span> <span class="o">=</span> <span class="p">[</span>
<span class="n">bundle</span><span class="p">(</span><span class="n">relative_to</span><span class="o">=</span><span class="s1">'config'</span><span class="p">,</span> <span class="n">fileset</span><span class="o">=</span><span class="p">[</span><span class="s1">'config/*'</span><span class="p">])</span>
<span class="p">]</span>
<span class="p">)</span>
</pre></div>
</div>
</p>
<p>Here, we keep the extra files in a subdirectory, <code>config/</code> so that they
don't clutter up this directory. (In this simple example, there's just
one file, so there isn't actually much clutter.) By using the
<a href="build_dictionary.html#bdict_bundle" pantsref="bdict_bundle"><code>bundle</code></a>'s
<code>relative_to</code> parameter, we "strip off" that
subdirectory; in the generated bundle, these extra files will be in the
top directory.</p>
<p>(If you want to set up a tree of static files but don't need it to be
runnable, you can define a <code>jvm_app</code> target with bundles (and/or
resources) but whose <code>jvm_binary</code> has no source or main; the resulting
bundle will have the files you want (along with a couple of
not-so-useful stub <code>.jar</code> files).)</p>
<h3 id="generating-a-bundle">Generating a Bundle</h3>
<p>Invoke <code>./pants bundle</code> on a JVM app or JVM binary target:</p>
<div class="codehilite"><pre><span></span>$ ./pants bundle examples/src/java/org/pantsbuild/example/hello/main:main
</pre></div>
<p>With options, you can tell Pants to archive the bundle in a zip, a tar, and some other common
formats. See the <a href="options_reference.html#oref_goal_bundle" pantsref="oref_goal_bundle">bundle help</a> for built-in choices.</p>
<h3 id="contents-of-a-bundle">Contents of a Bundle</h3>
<p>The generated bundle is basically a directory tree containing <code>.jar</code>s
and extra files. The <code>.jar</code> in the top-level directory has a manifest so
you can run it with <code>java -jar</code>:</p>
<div class="codehilite"><pre><span></span>$ <span class="nb">cd</span> dist/hello-example-bundle/
$ java -jar hello-example.jar
<span class="m">16</span>:52:11 INFO : Hello, world!
</pre></div>
<p>The "bundle" is basically a tree of files:</p>
<div class="codehilite"><pre><span></span>$ <span class="nb">cd</span> dist/hello-example-bundle/
$ find .
.
./greetee.txt
./hello-example.jar
./libs
$ jar -tf hello-example.jar
META-INF/
META-INF/MANIFEST.MF
com/
org/pantsbuild/
org/pantsbuild/example/
org/pantsbuild/example/hello/
org/pantsbuild/example/hello/main/
org/pantsbuild/example/hello/main/HelloMain.class
org/pantsbuild/example/
org/pantsbuild/example/hello/
org/pantsbuild/example/hello/world.txt
org/pantsbuild/example/hello/greet/
org/pantsbuild/example/hello/greet/Greeting.class
</pre></div>
<p>That <code>greetee.txt</code> file came from the <code>bundles=</code> parameter.
The <code>libs/</code> directory contains 3rdparty jars (if any). The <code>jar</code> in the top directory
contains code compiled for this target.</p>
<h3 id="deploying-a-bundle">Deploying a Bundle</h3>
<p>Instead of just creating a directory tree, you can specify <code>bundle --bundle-jvm-archive=zip</code> to
<code>./pants bundle</code> to generate an archive file (a <code>.zip</code>, monolithic <code>.jar</code>, or some other
format) instead.</p>
<p>To use such an archive, put it where you want it, unpack it, and run:</p>
<div class="codehilite"><pre><span></span>$ ./pants bundle --bundle-jvm-archive<span class="o">=</span>zip examples/src/java/org/pantsbuild/example/hello/main
...lots of build output...
<span class="m">10</span>:14:26 <span class="m">00</span>:01 <span class="o">[</span>create-monolithic-jar<span class="o">]</span>
<span class="m">10</span>:14:26 <span class="m">00</span>:01 <span class="o">[</span>add-internal-classes<span class="o">]</span>
<span class="m">10</span>:14:26 <span class="m">00</span>:01 <span class="o">[</span>jar-tool<span class="o">]</span>
created dist/hello-example.zip
<span class="m">10</span>:14:26 <span class="m">00</span>:01 <span class="o">[</span>dup<span class="o">]</span>
<span class="m">10</span>:14:26 <span class="m">00</span>:01 <span class="o">[</span>apk<span class="o">]</span>
<span class="m">10</span>:14:26 <span class="m">00</span>:01 <span class="o">[</span>apk-bundle<span class="o">]</span>
SUCCESS
$ <span class="c1"># let's use it:</span>
$ mkdir tmp<span class="p">;</span> <span class="nb">cd</span> tmp
$ unzip ../dist/hello-example.zip
Archive: ../dist/hello-example.zip
inflating: greetee.txt
inflating: hello-example.jar
$ java -jar hello-example.jar
Hello, Bundled-File World!
Hello, Resource World!
$
</pre></div>
<h2 id="omitting-or-shading-the-contents-of-a-binary">Omitting or Shading the Contents of a Binary</h2>
<h3 id="omitting">Omitting</h3>
<p>Sometimes you want to leave some files out of your binary.</p>
<p>You can omit jars from the binary by means of the <code>jvm_binary</code>'s <code>deploy_excludes</code> parameter.
For example, if you're making a binary to run on Hadoop and there are some "standard jars"
already on the destination machines, you can list those in <code>deploy_excludes</code>.</p>
<p>More generally, you can omit files from the binary jar with <code>deploy_jar_rules</code>. For example, a
3rdparty dependency might have a transitive dependency with a bad manifest file. If you try to run
the jar you might get <code>Invalid signature file digest for Manifest main attributes</code>. If you don't
actually use the code in that transitive dependency, you might work around the error by omitting
the dependency.</p>
<p>To tell Pants to omit some files from the binary, set the <code>deploy_jar_rules</code> parameter of
<a href="build_dictionary.html#bdict_jvm_binary" pantsref="bdict_jvm_binary"><code>jvm_binary</code></a> to a <a href="build_dictionary.html#bdict_jar_rules" pantsref="bdict_jar_rules"><code>jar_rules</code></a>.
E.g., to omit all files containing the regexp <code>Greeting</code>, you might set</p>
<div class="codehilite"><pre><span></span><span class="n">deploy_jar_rules</span><span class="o">=</span><span class="n">jar_rules</span><span class="p">(</span><span class="n">rules</span><span class="o">=</span><span class="p">[</span><span class="n">Skip</span><span class="p">(</span><span class="s1">'Greeting'</span><span class="p">)])</span>
</pre></div>
<p>After building our <code>hello</code> example, if we check the binary jar's contents, there is no
<code>Greeting.class</code> (and running that jar crashes; we omitted a class this binary needs):</p>
<div class="codehilite"><pre><span></span>$ ./pants binary examples/src/java/org/pantsbuild/example/hello/main:main
$ jar -tf dist/hello-example.jar
META-INF/
META-INF/MANIFEST.MF
com/
org/pantsbuild/
org/pantsbuild/example/
org/pantsbuild/example/hello/
org/pantsbuild/example/hello/main/
org/pantsbuild/example/hello/main/HelloMain.class
org/pantsbuild/example/
org/pantsbuild/example/hello/
org/pantsbuild/example/hello/world.txt
$
</pre></div>
<h3 id="shading">Shading</h3>
<p>Sometimes you have dependencies that have conflicting package or class names. This typically occurs
in the following scenario: Your jvm_binary depends on a 3rdparty library A (rev 1.0), and a 3rdparty
library B (rev 1.3). It turns out that A happens to also depend on B, but it depends on B (rev 2.0),
which is backwards-incompatible with rev 1.3. Now B (1.3) and B (2.0) define different versions of
the same classes, with the same fully-qualified class names, and you're pulling them all onto the
classpath for your project.</p>
<p>This is where shading comes in: you can rename the fully-qualified names of the classes that
conflict, typically by applying a prefix (eg, <code>__shaded_by_pants__.org.foobar.example</code>).</p>
<p>Pants uses jarjar for shading, and allows shading rules to be specified on <code>jvm_binary</code> targets with
the <code>shading_rules</code> argument. The <code>shading_rules</code> argument is a list of rules. Available rules
include: <a href="build_dictionary.html#bdict_shading_relocate" pantsref="bdict_shading_relocate"><code>shading_relocate</code></a>,
<a href="build_dictionary.html#bdict_shading_exclude" pantsref="bdict_shading_exclude"><code>shading_exclude</code></a>,
<a href="build_dictionary.html#bdict_shading_relocate_package" pantsref="bdict_shading_relocate_package"><code>shading_relocate_package</code></a>, and
<a href="build_dictionary.html#bdict_shading_exclude_package" pantsref="bdict_shading_exclude_package"><code>shading_exclude_package</code></a>.</p>
<p>The order of rules in the list matters, as typical of shading
logic in general.</p>
<p>These rules are powerful enough to take advantage of jarjar's more
advanced syntax, like using wildcards in the middle of package
names. E.g., this syntax works:</p>
<div class="codehilite"><pre><span></span><span class="c1"># Destination pattern will be inferred to be</span>
<span class="c1"># [email protected].@2</span>
<span class="n">shading_relocate</span><span class="p">(</span><span class="s1">'com.*.foo.bar.**'</span><span class="p">)</span>
</pre></div>
<p>Which can also be done by:</p>
<p>:::python
shading_relocate_package('com.*.foo.bar')</p>
<p>The default shading prefix is <code>__shaded_by_pants__</code>, but you can change it:</p>
<div class="codehilite"><pre><span></span><span class="n">shading_relocate_package</span><span class="p">(</span><span class="s1">'com.foo.bar'</span><span class="p">,</span> <span class="n">shade_prefix</span><span class="o">=</span><span class="s1">'__my_prefix__.'</span><span class="p">)</span>
</pre></div>
<p>You can rename a specific class:</p>
<div class="codehilite"><pre><span></span><span class="n">shading_relocate</span><span class="p">(</span><span class="s1">'com.example.foo.Main'</span><span class="p">,</span> <span class="s1">'org.example.bar.NotMain'</span><span class="p">)</span>
</pre></div>
<p>If you want to shade everything in a package except a particular file (or subpackage), you can use
the <a href="build_dictionary.html#bdict_shading_exclude" pantsref="bdict_shading_exclude"><code>shading_exclude</code></a> rule.</p>
<div class="codehilite"><pre><span></span><span class="n">shading_exclude</span><span class="p">(</span><span class="s1">'com.example.foobar.Main'</span><span class="p">)</span> <span class="c1"># Omit the Main class.</span>
<span class="n">shading_exclude_package</span><span class="p">(</span><span class="s1">'com.example.foobar.api'</span><span class="p">)</span> <span class="c1"># Omit the api subpackage.</span>
<span class="n">shading_relocate_package</span><span class="p">(</span><span class="s1">'com.example.foobar'</span><span class="p">)</span>
</pre></div>
<p>Again, order matters here: excludes have to appear <strong>first</strong>.</p>
<p>To see an example, take a look at <code>testprojects/src/java/org/pantsbuild/testproject/shading/BUILD</code>,
and try running</p>
<div class="codehilite"><pre><span></span>./pants binary testprojects/src/java/org/pantsbuild/testproject/shading
jar -tf dist/shading.jar
</pre></div>
<h2 id="target-scopes">Target Scopes</h2>
<h3 id="overview">Overview</h3>
<p>Pants supports marking targets with one or more <code>scope</code> values which the JVM backend will use to filter
dependency subgraphs at compiletime and runtime. Scopes are also used for unused dependency
detection: only <code>default</code> scoped targets are eligible to be considered as "unused" deps.</p>
<h3 id="correspondence-with-other-build-systems">Correspondence with other build systems</h3>
<p>Scopes in pants are similar to scopes in other build systems, with the fundamental difference
that they apply to targets (the "nodes" of the build graph), rather than to dependency "edges".
The reason that Pants differs in this regard is that, in a monorepo, it is strongly encouraged
to make changes to your dependency targets (which benefits all consumers) rather than to work
around an issue in a dependency by making a local change to your target.</p>
<h3 id="scope-values">Scope values</h3>
<p>Pants' built in scopes are:</p>
<ul>
<li><code>default</code>: The "default" scope when a scope is not specified on a target. <code>default</code> targets are
included on classpaths at both compiletime and runtime, and are the only targets eligible for
unused dep detection.</li>
<li><code>compile</code>: Indicates that a target is only used at compiletime, and should not be included
in runtime binaries or bundles. javac annotation processors or scalac macros are good examples
of compiletime-only dependencies.</li>
<li><code>runtime</code>: Indicates that a target is only used at runtime, and should not be presented to the
compiler. Targets which are only used via JVM reflection are good examples of runtime-only
dependencies.</li>
<li><code>test</code>: Indicates that a target is used when running tests. This scope is typically used in
addition to another scope (e.g.: <code>scope='compile test'</code>). Targets which are are provided by an
external execution environment are good examples of compile+test dependencies.</li>
<li><code>forced</code> <em>(available from pants 1.1.0)</em>: The <code>forced</code> scope is equivalent to the <code>default</code> scope, but additionally indicates
that a target is not eligible to be considered an "unused" dependency. It is sometimes necessary
to mark a target <code>forced</code> due to false positives in the static analysis used for unused
dependency detection; if possible, you should always prefer to mark a target <code>runtime</code> or
<code>compile</code> if that more accurately describes their usage.</li>
</ul>
<h3 id="setting-target-scopes">Setting target scopes</h3>
<p>To set the scope of a target, you should generally prefer to pass the <code>scope</code> parameter for
that target:</p>
<div class="codehilite"><pre><span></span><span class="n">java_library</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">'lib'</span><span class="p">,</span>
<span class="o">..</span><span class="p">,</span>
<span class="n">scope</span><span class="o">=</span><span class="s1">'runtime'</span><span class="p">,</span>
<span class="p">)</span>
</pre></div>
<p>Multiple scopes can be specified. The equivalent of Maven's <code>provided</code> scope can be expressed by
specifying both compile and test scopes.</p>
<div class="codehilite"><pre><span></span><span class="n">java_library</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">'lib'</span><span class="p">,</span>
<span class="o">..</span><span class="p">,</span>
<span class="n">scope</span><span class="o">=</span><span class="s1">'compile test'</span><span class="p">,</span>
<span class="p">)</span>
</pre></div>
<p>If the scope of a target is not matched for a particular context, the entire subgraph represented
by the dependency will be pruned. This means that if a dependency 'B' of a target 'A' is marked
<code>compile</code> (for example), the dependency targets of 'B' will only be included at compiletime (unless
'A' has other dependency paths to those targets).</p>
<p>One effect of this behavior is that you can introduce intermediate aliases to "re-scope" a target
when consumers need to use it in multiple ways:</p>
<div class="codehilite"><pre><span></span><span class="c1"># An alias of `:lib` which consumers can use to indicate that they only need it at compile time.</span>
<span class="n">target</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">'lib-compile'</span><span class="p">,</span>