We solve the gluing problem for the ^-invariant. Consider a generalized Dirac operator D over a compact Riemannian manifold M that is partitioned by a compact hypersurface N such that M :- Mχ UN M2 . We assume that the Riemannian metric of M and D have a product structure near N, i.e., D = I{d/dτ + DN) with some Dirac operator DN on N. Using boundary conditions of Atiyah-Patodi -Singer type parametrized by Lagrangian subspaces L, of kerD^ we define selfadjoint extensions D /, i = 1,2, over M{. We express the //-invariant of D in terms of the //-invariants of Di, an invariant m(Lι, L2) of the pair of the Lagrangian subspaces Lχ, L2 , which is related to the Maslov index and an integer-valued term J . In the adiabatic limit, i.e., if a tubular neighborhood of N is long enough, the vanishing of J is shown under certain regularity conditions. We apply this result in order to prove cutting and pasting formulas for the ^/-invariant, a Wall nonadditivity result for the index of Atiyah-Patodi -Singer boundary value problems and a splitting formula for the spectral flow. 1. The gluing problem and applications 1.1.. Introduction. We solve the gluing problem for the ^/-invariant of generalized Dirac operators. Consider a closed, compact Riemannian manifold carrying a Dirac bundle with a generalized Dirac operator. Assume that this manifold is separated into two pieces by a compact hypersurface. The gluing problem for the ^/-invariant consists in expressing the ^/-invariant of the original Dirac operator in terms of the ^/-invariants of the Dirac operators living on the pieces. The selfadjoint operators on the two components with boundary depend on a boundary condition given by Lagrangian subspaces Lx, L2 of a certain symplectic vector space. The gluing formula also contains an additional real-valued term m(L{, L2), which is nicely related to the symplectic geometry and the Maslov index.